谁能帮助,我似乎无法修复该错误回报,而试图解析这个API:Android的JSON解析
{
"createDate": 1321834118923,
"result": "SUCCESS",
"searchTerm": "N7",
"searchableLocations": [
{
"identifier": "OUTCODE^1685",
"name": "N7"
}
]
}
请帮我找出问题
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");
}
}
我建议你使用谷歌的GSON库:http://code.google.com/p/google-gson/ – binnyb