JSON to Object and Array in Java

Try this snippet to convert JSON text into object and/or array in Java:

JSONObject object = new JSONObject(jsontext);
JSONArray array = jsonObj.getJSONArray("somearray");
for (int i = 0; i < somearray.length(); i++) {
	JSONObject item = somearray.getJSONObject(i);
	String somevalue = item.getString("somekey");
}

jsontext is your JSON text.

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *