can some parse the json encode response from php into java arraylist. My string is
[{"Link_Id":"811"},{"Link_Id":"1389"},{"Link_Id":"6190"}]
what I tried is
static JSONObject jObj = null;
JSONArray link_Ids = null;
ArrayList<Integer> ids;
jObj = new JSONObject(a);
link_Ids = jObj.getJSONArray("Link_Id");
for (int i = 0; i < link_Ids.length(); i++) { // **line 2**
JSONObject childJSONObject = link_Ids.getJSONObject(i);
ids.add(childJSONObject.getString(i));
}
can some one please correct me
the string represents a json array so it should be like this:
link_Ids = new JSONArray(a);
for (int i = 0; i < link_Ids.length(); i++) {
JSONObject childJSONObject = link_Ids.getJSONObject(i);
ids.add(childJSONObject.getString("Link_Id"));
}
You can use gson library for parsing JSON objects.It's Easy to use.Here is the Link for gson parsing
Here is the Stack Overflow internal link
For gson to work to need a .jar file.You can download the gson library from here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.