JSONArray nearbyCities = products.getJSONArray("nearby-cities");
JSONObject nearbyCititesObj = content.getJSONObject("nearby-cities.json");
要检索的对象是properties->product->nearly-cities->contents->nearly-cities.json。
这里要检索的问题是 nearby-cities
和 nearby-cities.json
对象和数组。
以下是json文件的链接 https:/earthquake.usgs.govearthquakesfeedv1.0detailnc73408691.geojson。
连字符不会有任何区别。你的错误可能在其他地方
response.getJSONObject("properties").getJSONObject("products").getJSONArray("nearby-cities").getJSONObject(0).getJSONObject("contents").getJSONObject("nearby-cities.json").toString();
这一行给出了预期的输出