私のAndroidアプリでこのJSONデータを解析する際に問題があります:
[{"personid":20,"personName":"Ross Gallagher update3","email":"ross_gallagher@rossgallagher.co.uk","birthday":{"date":"2013-01-01 00:00:00","timezone_type":3,"timezone":"America\/Los_Angeles"},"anniversary":{"date":"1900-01-01 00:00:00","timezone_type":3,"timezone":"America\/Los_Angeles"},"Credit":2}]
私が得ているエラーは次のとおりです。
W/System.err: org.json.JSONException: Value [{"birthday":{"date":"2013-01-01 00:00:00","timezone":"America\/Los_Angeles","timezone_type":3},"anniversary":{"date":"1900-01-01 00:00:00","timezone":"America\/Los_Angeles","timezone_type":3},"email":"ross_gallagher@rossgallagher.co.uk","personName":"Ross Gallagher update8","Credit":2,"personid":20}] of type org.json.JSONArray cannot be converted to JSONObject
私のJSONパーサーコードは次のとおりです。
public JSONObject getJSONFromUrl(String url)
{
HttpEntity httpEntity = null;
JSONObject respObject = null;
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(httpEntity != null){
try {
respObject = new JSONObject(EntityUtils.toString(httpEntity));
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//....
}
// return JSON
return respObject;
}
必要なのは、この JSON オブジェクトから誕生日の詳細を、名前、電子メール、クレジット、記念日とともに引き出すことだけです。
アドバイスをいただければ幸いです。