基本上我正在尝试制作一个天气应用程序。我试图检索一些数据(假设来自 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/