helloDroid helloDroid - 1 year ago 97
JSON Question

How to parse json string in Android?

Possible Duplicate:

JSON Array iteration in Android/Java

I am fetching JSON string from server and I have already got JSON string by code.
But I didn't understand how to parse it.

Below is my JSON string

"university": {
"name": "oxford",
"url": "http://www.youtube.com"
"1": {
"id": "2",
"title": "Baseball",
"datetime": "2011-11-11 10:41:46"
"2": {
"id": "1",
"title": "Two basketball team players earn all state honors",
"datetime": "2011-11-11 10:40:57"

Please provide any guidance or code snippet.

Answer Source

Use JSON classes for parsing e.g

JSONObject mainObject = new JSONObject(Your_Sring_data);
JSONObject uniObject = mainObject.getJSONObject("university");
String  uniName = uniObject.getJsonString("name");
String uniURL = uniObject.getJsonString("url");

JSONObject oneObject = mainObject.getJSONObject("1");
String id = oneObject.getJsonString("id");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download