Making JSON in android -


i need make json on android -

{     "warp":[         {             "type":"cotton",             "property":"carded",             "count":"10"         },         {             "type":"cotton",             "property":"carded",             "count":"10"         }     ] } 

i tried

j = new jsonobject();  j2.put("type", "cotton"); j2.put("property", "carded"); j2.put("count", "10");  = new jsonarray(); a.put("warp", j2); 

but looks cannot directly put jsonarray inside jsonobject this.

any appreciated.

do this:

// create object jsonobject objectinarray = new jsonobject(); objectinarray.put("type", "cotton"); objectinarray.put("property", "carded"); objectinarray.put("count", "10");  // create array , add object jsonarray array = new jsonarray(); array.put(objectinarray);  // create object , add array on "wrap" jsonobject wrapobject = new jsonobject(); wrapobject.put("wrap", array); 

Comments