json - 如果 JSON 对象名称包含连字符或破折号 (-),如何在 android studio 中使用 Volley Library 获取类似“附近城市”的 JSON 对象名称?
问题描述
JSONArray nearbyCities = products.getJSONArray("nearby-cities");
JSONObject nearbyCititesObj = content.getJSONObject("nearby-cities.json");
要检索的对象是 properties->products->nearby-cities->contents->nearby-cities.json
这里要检索的问题分别是对象nearby-cities
和nearby-cities.json
数组。
下面是 json 文件的链接 https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc73408691.geojson
解决方案
连字符不会有任何区别。您的错误可能在其他地方
response.getJSONObject("properties").getJSONObject("products").getJSONArray("nearby-cities").getJSONObject(0).getJSONObject("contents").getJSONObject("nearby-cities.json").toString();
这一行给出了预期的输出
推荐阅读
- azure-cdn - 如何修复 Azure CDN 返回的 ERR_HTTP2_PROTOCOL_ERROR?
- android - 如何使用 Delphi for Android 创建带圆角的 TEdit?
- python - Pythonic 方式的 try/except 对象变量设置
- sql - 在 JSON 解析后从 Google 脚本中的 sql 查询输出中检索记录/值
- c# - BottomNavigationBar 上方的按钮
- javascript - VB.NET 正在创建新的 cookie,而不是更新现有的
- python - 在python中将整数转换为日期
- kubernetes - Kubernetes:无法加入不同的子网 - TLS Bootstrap 超时
- javascript - js对象,按键排序,随机顺序
- haskell - IO 中的就地更新