gpt4 book ai didi

android json响应键值,解析

转载 作者:行者123 更新时间:2023-11-29 22:14:25 25 4
gpt4 key购买 nike

我从 Web 服务获得 JSON 响应:

{"CoverageSearchByLatLongResult":{"HasTransmissionAreasWithSignal":true,"SwitchOffArea": 
{"OpenForVastApplications":false,"SeperateTileSetUrl":"http:\/\/myswitch.merged.stage.orchard.net.au\/geodatafiles\/SwitchOffArea\/442b8844-3c05-4548-9424-
4fdafc1f3c62\/Seperate","HASStatus":"Future","HASStatement":"<p>The Household Assistance Scheme is not yet available in this switchover area. Eligible households will be sent a letter when the scheme opens in the Sydney area.<\/p>","SwitchOffDate":"31 December 2013","Events":{"MaximumProximity":6.864859435168742,"Items":[{"Name":"Test Event","Time":"Time","Url":"","Date":"Date","Address":"19a Boundary Street, Rushcutter...

所以我的问题是,在 android java 中如何请求 key :CoverageSearchByLatLongResult

在 iphone 中的 ObjC 中,是这样的:

  NSDictionary *coverageResult = [response objectForKey:@"CoverageSearchByLatLongResult"];

所以基本上我是用一个键来解析一个字典,但是我需要把这个结果放在其他字典中,

[如果错误请指正,在 Java 字典中称为映射?]

如何做到这一点?

非常感谢!

最佳答案

您应该使用 org.json 包中的类:

http://developer.android.com/reference/org/json/package-summary.html

有了它们,您可以执行以下操作:

try {
String jsonString = "YOUR JSON CONTENT";
JSONObject obj = new JSONObject(jsonString);
JSONObject anotherObj = obj.getJSONObject("CoverageSearchByLatLongResult");
boolean bool = anotherObj.getBoolean("HasTransmissionAreasWithSignal");

JSONArray jsonArray = obj.getJSONArray("arrayKey");
int i = jsonArray.getInt(0);
} catch (JSONException e) {
e.printStackTrace();
}

Java Maps 将键映射到值。作为它们的使用示例:

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("string key", 1);
map.put("another key", 3);

关于android json响应键值,解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8812152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com