qq_41979210
qq_41979210
2018-12-28 20:00

按照第一行代码上打酷欧天气提示我 Value Request of type java.lang.String cannot be converte

  • android-studio
  • android

12-28 19:54:35.763 7686-8889/com.example.administrator.kuou W/System.err: org.json.JSONException: Value Request of type java.lang.String cannot be converted to JSONObject
12-28 19:54:35.763 7686-8889/com.example.administrator.kuou W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
12-28 19:54:35.763 7686-8889/com.example.administrator.kuou W/System.err: at org.json.JSONObject.(JSONObject.java:160)
12-28 19:54:35.763 7686-8889/com.example.administrator.kuou W/System.err: at org.json.JSONObject.(JSONObject.java:173)
12-28 19:54:35.763 7686-8889/com.example.administrator.kuou W/System.err: at com.example.administrator.kuou.util.Utility.handleWeatherResponse(Utility.java:125)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at com.example.administrator.kuou.WeatherActivity$1.onResponse(WeatherActivity.java:91)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
12-28 19:54:35.764 7686-8889/com.example.administrator.kuou W/System.err: at java.lang.Thread.run(Thread.java:760)
12-28 19:54:35.764 7686-7686/com.example.administrator.kuou D/TAG: run: null
12-28 19:54:35.782 7686-7686/com.example.administrator.kuou I/Toast: Show toast from OpPackageName:com.example.administrator.kuou, PackageName:com.example.administrator.kuou


```public static Weather handleWeatherResponse(String response) {
        try {
            // 将整个json实例化保存在jsonObject中
            JSONObject jsonObject = new JSONObject(response);
            // 从jsonObject中取出键为"HeWeather"的数据,并保存在数组中
            JSONArray jsonArray = jsonObject.getJSONArray("Weather");
            // 取出数组中的第一项,并以字符串形式保存
            String weatherContent = jsonArray.getJSONObject(0).toString();
            // 返回通过Gson解析后的Weather对象
            return new Gson().fromJson(weatherContent, Weather.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答