android json key,android json response key value, parsing

这篇博客讨论了如何在Android中解析JSON响应并获取特定对象。使用`org.json`包,可以创建`JSONObject`来解析JSON字符串,并通过调用`getJSONObject`方法获取指定键的值。例如,要获取`CoverageSearchByLatLongResult`对象,可以将其转换为另一个`JSONObject`。此外,还提到了Java中的字典(映射)操作。
摘要由CSDN通过智能技术生成

问题

i get a JSON response from a web service:

{"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":"

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.","SwitchOffDate":"31 December 2013","Events":{"MaximumProximity":6.864859435168742,"Items":[{"Name":"Test Event","Time":"Time","Url":"","Date":"Date","Address":"19a Boundary Street, Rushcutter...

so my question is, in android java how to ask for the key: CoverageSearchByLatLongResult

in ObjC in iphone , something like this:

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

so basically im parsing a dictionary with a key, but that result i need to put it inside other dictionary,

[correct me if wrong, in java dictionaries are called maps?]

how to do this?

thanks a lot!

回答1:

You should use the classes in the org.json package:

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

With them you can do things like:

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 keys to values. As an example of their use:

Map map = new HashMap();

map.put("string key", 1);

map.put("another key", 3);

来源:https://stackoverflow.com/questions/8812152/android-json-response-key-value-parsing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值