java - Process JSONObject to get the items -
this code:
jsonobject jsonobj= jsonobject.fromstring(request.getparameter("parameter")); system.out.println(jsonobj.getstring("dlist"));
gave me string:
["abc","cgr","drr"]
how process values? tried getting jsonarray like,
jsonarray arr= jsonobj.getjsonarray("dlist");
but showing following error.
jsonobject["dlist"] not jsonarray.
here raw data:
{"sort":null, "filterfunction":null, "source":["abc","cgr","drr"], "length":3, "source":["abc","cgr","drr"], "length":3}}
i passing dlist
json.encode(dlist.source)
flex
.
to jsonobject in json array jsonobject object = jsonarray.getjsonobject(index); values json object json values should key , value pair format jsonobject myjson = new jsonobject(myjsonstring); string name = myjson.get("name"); **example** string s = "{menu:{\"1\":\"sql\", \"2\":\"android\", \"3\":\"mvc\"}}"; jsonobject jobject = new jsonobject(s); jsonobject menu = jobject.getjsonobject("menu"); map<string,string> map = new hashmap<string,string>(); iterator iter = menu.keys(); while(iter.hasnext()){ string key = (string)iter.next(); string value = menu.getstring(key); map.put(key,value); }
Comments
Post a Comment