1)导入JSONObject库
2) 我在gradle文件中添加了"org.json:json:2014113"作为依赖项。
3) 更新了jar文件。
不确定如何解决此问题。任何帮助都将不胜感激。
private CurrentWeather getCurrentDetails(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
String timezone = forecast.getString("timezone");
Log.i(TAG, "From JSON: " + timezone);
JSONObject currently = new forecast.getJSONObject("currently");
安卓工作室无法识别getJSONObject,尽管它是一个自动完成的建议。
编译错误如下:
error: package forecast does not exist
尝试的解决方案:Cannon解析符号JSONObject(Android Studio)
您的问题就在这一行:
JSONObject currently = new forecast.getJSONObject("currently");
您不需要使用new
来获取JSONObject,IDE认为预测是一种类型或包,并且在您的项目中找不到它,所以它抛出了一个错误,您应该将前一行更改为:
JSONObject currently = forecast.getJSONObject("currently");
希望它能帮助你,快乐编码。