ULLAS K ULLAS K - 1 year ago 235
JSON Question

How to Convert JSON String arrray to Json Array list

I have Json String array ,which looks like this ,

{ {name:"214",value:true,Id:0},

and want to covert this string to Json array object and iterate the list to read each object's value. Then set values to corresponding dto and save it .
But i didnt find any good way to convert normal JSON array string to json array object.

I am not using google json , I want it to be done in normal json itself .Please help me

and java class i want something like this

JSONObject[] jsonObjectList = String after convert();

for (JSONObject jsonObject : jsonObjectList) {
System.out.println(" name is --"+jsonObject.get("name"));
System.out.println(" value is ---"+jsonObject.get("value"));
System.out.println(" id is ----"+jsonObject.get("id"));


Answer Source

Here is the example for parsing json Object.. use JSON lib for this..

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
public class TestJson {
    public static void parseProfilesJson(String jsonStr) {
        try {
            JSONArray nameArray = (JSONArray) JSONSerializer.toJSON(jsonStr);
            for(Object js : nameArray){
                JSONObject json = (JSONObject) js;
        } catch (JSONException e) {
    public static void main(String[] args) {
        String s = "[{\"date\":\"2012-04-23\",\"activity\":\"gym\"},{\"date\":\"2012-04-24\",\"activity\":\"walking\"}]";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download