I have tried several tutorials using JSON parsing but I can't seem to make them work. Please can anyone kindly help and direct me to the right direction?
I have now made some changes to my previous class with the help of a couple of helpful people, and I'm now getting less errors. Please help.
package com.somcollection;
import android.app.Activity;
import android.os.Bundle;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
public class JsonParser extends Activity {
private JSONObject jObject;
private String jString = "{\"searchTerm\":\"N7\",\"searchableLocations\":[{\"identifier\":\"OUTCODE^1685\",\"name\":\"N7\"}],\"createDate\":1321834118923,\"result\":\"SUCCESS\"}";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
parse();
} catch (Exception e) {
e.printStackTrace();
}
}
private void parse() throws Exception {
jObject = new JSONObject(jString);
JSONObject jObject = new JSONObject(jString);
String menuObject = jObject.getString("searchTerm");
JSONArray menuitemArray = jObject.getJSONArray("searchableLocations");
for (int i = 0; i < menuitemArray.length(); i++) {
JSONObject jsonObj = menuitemArray.getJSONObject(i);
String attributeId = jsonObj.getString("identifier");
System.out.println(attributeId);
String attributeValue = jsonObj.getString("name");
System.out.println(attributeValue);
}
String createDate = jObject.getString("jObject");
String result = jObject.getString("result");
}
}
for(inti=0i<searchableLocations.length()typo?