如何在android studio中使用Volley Library获取包含连字符或破折号(-)的JSON对象名称,如 "neomorrow-cities"?

问题描述 投票:-1回答:1
JSONArray nearbyCities = products.getJSONArray("nearby-cities");
JSONObject nearbyCititesObj = content.getJSONObject("nearby-cities.json");

要检索的对象是properties->product->nearly-cities->contents->nearly-cities.json。

这里要检索的问题是 nearby-citiesnearby-cities.json 对象和数组。

以下是json文件的链接 https:/earthquake.usgs.govearthquakesfeedv1.0detailnc73408691.geojson。

json android-studio android-volley
1个回答
0
投票

连字符不会有任何区别。你的错误可能在其他地方

response.getJSONObject("properties").getJSONObject("products").getJSONArray("nearby-cities").getJSONObject(0).getJSONObject("contents").getJSONObject("nearby-cities.json").toString();

这一行给出了预期的输出

© www.soinside.com 2019 - 2024. All rights reserved.