2

my JSONArray is

[
   {"id":1,
    "programs_idprograms":3,
    "description":"course description",
    "idCourse":"course title"
   },
   {"id":2,
    "programs_idprograms":3,
    "description":"course description2",
    "idCourse":"course title2"
   }
]  

is stored in a string called bean2

2
  • 1
    Use Gson or Jackson to parse it and then send it to JSP Commented Jan 4, 2015 at 15:06
  • You will need some json parser Commented Jan 4, 2015 at 15:07

2 Answers 2

1
JSONArray array = new JSONArray(bean2);
for(int i=0;i<array.length();i++){
    JSONObject object = array.getJSONObject(i);
    int id = object.getInt("id");
    int programs_idprograms = object.getInt("programs_idprograms");
    String description = object.getString("description");
    String idCourse = object.getString("idCourse");   
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try it:

jsonArray = [ {"id":1,
"programs_idprograms":3,
"description":"course description",
"idCourse":"course title"
},  ... ];

One way to do it is to construct the html in Javascript code like this:

 var myHTMLStr = '<table>';
 for(var i in jsonArray) {
 myHTMLStr+='<tr><td>' + jsonArray[i]['id'] + '</td><td>' + jsonArray[i]  ['programs_idprograms'] +   '</td></tr>';

 }
myHTMLStr+='</table>';

Now display the HTML string:

document.getElementById('tableOutput').innerHTML = myHTMLStr;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.