I have this section of code (note that responseBody truly comes from a web server).
public JSONObject getObj(){
String responseBody = '[{"zip":"56601","city":"Bemidji","state":"MN","county":"Beltrami","dist":"0.14802"},{"zip":"56619","city":"Bemidji","state":"MN","county":"Beltrami","dist":"3.98172"}]';
JSONObject response = null;
try{
response = new JSONObject(responseBody);
}catch(JSONException ex){
Logger.getLogger(Http.class.getName()).log(Level.SEVERE, null, ex);
}
return response;
}
I don’t understand why JSONObject is throwing an exception. What is making it do that?
This is a JSONArray with a JSONObject in it not a JSONObject.
see this link:
http://www.w3schools.com/json/json_syntax.asp