我是iOS新手,我想解析数据,但它太复杂了,我不知道如何解析它。下面给出的是json数据。
{
"response_code": 200,
"last_updated": {
"date": "2015-12-27",
"time": "01:32:13"
},
"trains": [
{
"train": {
"number": "04921",
"start_time": "04:45",
"name": "SRE-UMB MEMU SPECIAL",
"type": "HSP"
},
"dest": {
"code": "UMB",
"name": "AMBALA CANT JN"
},
"source": {
"code": "SRE",
"name": "SAHARANPUR"
}
},
{
"train": {
"number": "04922",
"start_time": "20:45",
"name": "UMB-SRE MEMU SPECIAL",
"type": "HSP"
},
"dest": {
"code": "SRE",
"name": "SAHARANPUR"
},
"source": {
"code": "UMB",
"name": "AMBALA CANT JN"
}
}
]
}
答案 0 :(得分:0)
{ , , }
- 它是一本字典
[ , , ]
- 它是一个数组
在你的情况下,你得到:
第一级 - 包含键response_code
,last_updated
,trains
的词典。
其中:
response_code
- 值
last_updated
- 包含密钥date
,time
的词典
trains
- 包含密钥train
,dest
,source
等
答案 1 :(得分:0)
使用NSJSONSerialization课程,这很简单。
例如,在Objective-C中:
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (jsonObject) {
// jsonObject is an NSArray or NSDictionary representation of the data that you can now do something with
}