Android的JSON响应键值,解析 [英] android json response key value, parsing
问题描述
我从一个Web服务的JSON响应:
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":"<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如何索要键:CoverageSearchByLatLongResult
so my question is, in android java how to ask for the key: CoverageSearchByLatLongResult
在ObjC在iphone,是这样的:
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,
[如有错误纠正我,java中词典被称为地图?]
[correct me if wrong, in java dictionaries are called maps?]
如何做到这一点?
非常感谢!
推荐答案
您应在org.json包中的类:
You should use the classes in the org.json package:
http://developer.android.com/reference/org/ JSON /包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的地图地图键的值。由于其使用的例子:
Java Maps map keys to values. As an example of their use:
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("string key", 1);
map.put("another key", 3);
这篇关于Android的JSON响应键值,解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!