我遇到了字符串无法转换为 JSONObject 的问题。有人可以帮助解决这个问题吗?感谢并非常感谢您的帮助。
protected void onPostExecute(String result) {
if (result==null || result.length()==0){
// no result:
return;
}
//clear the list
moviesList.clear();
try {
//turn the result into a JSON object
JSONObject responseObject = new JSONObject("results");
// get the JSON array named "results"
JSONArray resultsArray = responseObject.getJSONArray(result);
// Iterate over the JSON array:
for (int i = 0; i < resultsArray.length(); i++) {
// the JSON object in position i
JSONObject messageObject = resultsArray.getJSONObject(i);
// get the primitive values in the object
String title = messageObject.getString("title");
String details = messageObject.getString("synopsis");
//put into the list:
Movie movie = new Movie(title, details, null,null);
moviesList.add(movie);
}
} catch (JSONException e) {
e.printStackTrace();
}
//refresh listView:
adapter.notifyDataSetChanged();
}
}
结果有价值
错误在以下行:
JSONObject responseObject = new JSONObject("results");