【问题标题】:Cannot resolve symbol getJSONObject in Android Studio无法在 Android Studio 中解析符号 getJSONObject
【发布时间】:2023-03-27 03:04:01
【问题描述】:

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");

Android Studio 无法识别 getJSONObject,即使它是作为自动完成建议出现的。

编译错误如下:

 error: package forecast does not exist

尝试的解决方案: Cannont resolve symbol JSONObject (Android Studio)

【问题讨论】:

    标签: android json android-studio


    【解决方案1】:

    您的问题出在这一行:

    JSONObject currently = new forecast.getJSONObject("currently");
    

    你不需要使用new来获取JSONObject,IDE认为预测是一个类型或者一个包并且它在你的项目中找不到它所以它会抛出一个错误,你应该改变上一行对此:

    JSONObject currently = forecast.getJSONObject("currently");
    

    希望对您有所帮助,祝您编码愉快。

    【讨论】:

    • 非常感谢。对此非常非常新:)
    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2019-02-07
    • 2015-07-28
    • 2014-06-24
    相关资源
    最近更新 更多