android - 在检索 json 数据时遇到问题。如何找回它

标签 android json parsing

基本上我正在尝试制作一个天气应用程序。我试图检索一些数据(假设来自 crood 对象的 lat 和 lon),但是每当我运行该应用程序时,它都没有向我显示任何错误,但它在 logcat 中显示一个异常,上面写着“没有 crood 的值(value)”。我已经尝试了我拥有的所有资源,但我无法将数据显示到 TextView 。

这是我想要定位的json

{"coord":{"lon":-0.13,"lat":51.51},"weather":      [{"id":721,"main":"Haze","description":"haze","icon":"50d"},     {"id":501,"main":"Rain","description":"moderate rain","icon":"10d"},  {"id":311,"main":"Drizzle","description":"rain and drizzle","icon":"09d"}],"base":"stations","main":{"temp":286.15,"pressure":1013,"humidity":87,"temp_min":286.15,"temp_max":286.15},"visibility":10000,"wind":{"speed":3.1,"deg":200},"clouds":{"all":75},"dt":1445700000,"sys":  {"type":1,"id":5089,"message":0.0153,"country":"GB","sunrise":1445668823,"sunset":1445705286},"id":2643743,"name":"London","cod":200}

我是这样做的

            String finalJson=buffer.toString();

            JSONObject parentObject = new JSONObject(finalJson);
            JSONObject jsonObject =parentObject.getJSONObject("crood");

如果有人帮我解决这个逻辑如何解析它。我想从这些数据中获取纬度、经度、名称、描述、温度和压力,并且我想在 TextView 中显示它。

最佳答案

问题出在 key 上。我用错了 key 。 :3 crood 而不是 coord

关于android - 在检索 json 数据时遇到问题。如何找回它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33329650/

相关文章:

c++ - 将 char 和 int 的随机序列的字符串解析为单独的 vector

.net - 使用正则表达式查找匹配的括号

java - 添加到我的方法快速文档描述(android studio)

android - 非法状态异常 : Fragment already added - during app startup on Android OS 4. 3

php - 如何从 PHP 解析 json(提要)

.net - 是否有一种经过验证的方法可以在 .NET 中非常快速地访问非常大(> 1 GB)二进制文件的特定区域

java - 如何在 android 中解决 StringIndexOutOfBoundsException

android - Android Manifest INSTALL_FAILED_VERSION_DOWNGRADE字符串资源Gradle

java - 转换为 JSONArray 时保持 List<LinkedHashMap<String,Object>> 顺序

json - 在获取 json 数据和 http 文件时出现异常