【发布时间】:2014-12-29 07:30:04
【问题描述】:
我有这段正在运行的代码,现在突然抛出一个 Cast 异常。有没有人经历过类似的事情?谢谢。
@Override
public List<RecordJSONclass> handleResponse(HttpResponse response)
throws IOException {
List<RecordJSONclass> result = new ArrayList<RecordJSONclass>();
String JSONResponse = new BasicResponseHandler().handleResponse(response);
try {
JSONObject object = (JSONObject) new JSONTokener(JSONResponse).nextValue();
JSONObject earthquakes = object.getJSONObject("data");
JSONArray temp = earthquakes.getJSONArray("temperature");
JSONArray prob = earthquakes.getJSONArray("pop");
正在扔一个
java.lang.ClassCastException: java.lang.String 无法转换为 org.json.JSONObject 在 myxmlparser.ResponseHandlerJSON.handleResponse(ResponseHandlerJSON.java:22)
异常发生在行
JSONObject 对象 = (JSONObject) 新 JSONTokener(JSONResponse).nextValue();
但是,在 http://developer.android.com/reference/org/json/JSONTokener.html 的类概述中作为示例传递了一个字符串
【问题讨论】: