我在 android LogCat 中收到此错误消息
04-24 21:14:02.603: W/System.err(831): org.json.JSONException: Value {"id":"602414132","first_name":"Adham","username":"adham.enaya","locale":"en_GB","link":"http:\/\/www.facebook.com\/adham.enaya","name":"Adham Enaya","last_name":"Enaya","gender":"male"} of type org.json.JSONObject cannot be converted to JSONArray
04-24 21:14:02.603: W/System.err(831): at org.json.JSON.typeMismatch(JSON.java:107)
04-24 21:14:02.603: W/System.err(831): at org.json.JSONArray.<init>(JSONArray.java:91)
04-24 21:14:02.603: W/System.err(831): at org.json.JSONArray.<init>(JSONArray.java:103)
04-24 21:14:02.615: W/System.err(831): at pit.opensource.readjson.D0ReadJSONWebServiceActivity.pasreJSON(D0ReadJSONWebServiceActivity.java:85)
04-24 21:14:02.623: W/System.err(831): at pit.opensource.readjson.D0ReadJSONWebServiceActivity.access$0(D0ReadJSONWebServiceActivity.java:78)
04-24 21:14:02.623: W/System.err(831): at pit.opensource.readjson.D0ReadJSONWebServiceActivity$DownloadFBUser.doInBackground(D0ReadJSONWebServiceActivity.java:108)
04-24 21:14:02.623: W/System.err(831): at pit.opensource.readjson.D0ReadJSONWebServiceActivity$DownloadFBUser.doInBackground(D0ReadJSONWebServiceActivity.java:1)
04-24 21:14:02.623: W/System.err(831): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-24 21:14:02.633: W/System.err(831): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-24 21:14:02.633: W/System.err(831): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-24 21:14:02.633: W/System.err(831): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-24 21:14:02.633: W/System.err(831): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-24 21:14:02.633: W/System.err(831): at java.lang.Thread.run(Thread.java:1019)
有什么问题,我认为是字符串编码?!
更新:
代码在这里
//Download text -------------------------------------------------------------
private String DownloadText(String urlString){
InputStream in = null;
StringBuilder sb = new StringBuilder();
try{
in = OpenHttpConnection(urlString);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line="";
while((line = br.readLine())!= null){
sb.append(line);
}
}catch(IOException ex){
}
return sb.toString();
}
//Parse JSON text -----------------------------------------------------------
private FBUser pasreJSON(String url){
FBUser user = null;
JSONArray json;
Log.d("JSON----------------",DownloadText(url));
try {
user = new FBUser();
json = new JSONArray(DownloadText(url));
for(int i=0;i<json.length();i++){
JSONObject object = json.getJSONObject(i);
user.id = object.getString("id");
user.name = object.getString("name");
user.first_name = object.getString("first_name");
user.last_name = object.getString("last_name");
user.link = object.getString("link");
user.username = object.getString("username");
user.gender = object.getString("gender");
user.locale = object.getString("locale");
}
} catch (JSONException e) {
e.printStackTrace();
}
return user;
}