java - How to Use JSON Accumulate Method With List? -
I'm trying to code below ....
public string list tojsonString ( String keyName, list; styleAttribute & gt; attrs) {JSONObject json = new JSONObject (); Json.accumulate (keyName, attrs); Return json.toString (); } But when I'm checking the json variable, something like this happens in empty values {"MyKey": {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}, {}, {}, {}, }, {}}}
And when I am checking the attrs variable, it has 22 element data. What am I doing wrong here? I'm just converting my list to a Jason object and saving the database. I am using import net.sf.json.JSONArray; Import net sf.json.JSONException; Import net sf.json.JSONObject;
You can use the code below
Public String ListToJsonString (List & Style; Attribute) {JSONObject jObject = new JSONObject (); Try {JSONArray jArray = New JSONArray (); (MyClass myObject: attrs) {JSONObject styleJSON = New JSONObject (); StyleJSON.put ("name", myObject.getName ()); Stylejson.eput ("roll number", myObject.getRollNumber ()); JArray.add (styleJSON); } JObject.put ("keyName", jArray); } Hold (exception JSE) {} return jObject.toString (); } This will solve your problem.
Comments
Post a Comment