这是我的php页面中的json。这是一本字典的Arrary还是只是一把字典,里面有钥匙和字典?我认为这是第二种选择,但我不确定,因为我的选项相互矛盾。一旦它在xcode调试器中显示,结构也会改变吗?
{
"slots": {
"2012-08-31 00:00:00 America/Los_Angeles": [
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-30 17:00:00 America/Los_Angeles",
"end": "2012-08-30 17:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-30 17:30:00 America/Los_Angeles",
"end": "2012-08-30 18:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": false,
"isReserved": false,
"label": " ",
"begin": "2012-08-30 18:00:00 America/Los_Angeles",
"end": "2012-08-31 00:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": false,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 00:00:00 America/Los_Angeles",
"end": "2012-08-31 08:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 08:00:00 America/Los_Angeles",
"end": "2012-08-31 08:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 08:30:00 America/Los_Angeles",
"end": "2012-08-31 09:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 09:00:00 America/Los_Angeles",
"end": "2012-08-31 09:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 09:30:00 America/Los_Angeles",
"end": "2012-08-31 10:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": false,
"isReserved": true,
"label": "Joe Smith",
"begin": "2012-08-31 10:00:00 America/Los_Angeles",
"end": "2012-08-31 12:30:00 America/Los_Angeles",
"span": 5
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 12:30:00 America/Los_Angeles",
"end": "2012-08-31 13:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 13:00:00 America/Los_Angeles",
"end": "2012-08-31 13:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 13:30:00 America/Los_Angeles",
"end": "2012-08-31 14:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 14:00:00 America/Los_Angeles",
"end": "2012-08-31 14:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 14:30:00 America/Los_Angeles",
"end": "2012-08-31 15:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 15:00:00 America/Los_Angeles",
"end": "2012-08-31 15:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 15:30:00 America/Los_Angeles",
"end": "2012-08-31 16:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 16:00:00 America/Los_Angeles",
"end": "2012-08-31 16:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 16:30:00 America/Los_Angeles",
"end": "2012-08-31 17:00:00 America/Los_Angeles",
"span": 1
}
],
"2012-09-01 00:00:00 America/Los_Angeles": [
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 17:00:00 America/Los_Angeles",
"end": "2012-08-31 17:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 17:30:00 America/Los_Angeles",
"end": "2012-08-31 18:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": false,
"isReserved": false,
"label": " ",
"begin": "2012-08-31 18:00:00 America/Los_Angeles",
"end": "2012-09-01 00:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": false,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 00:00:00 America/Los_Angeles",
"end": "2012-09-01 08:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 08:00:00 America/Los_Angeles",
"end": "2012-09-01 08:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 08:30:00 America/Los_Angeles",
"end": "2012-09-01 09:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 09:00:00 America/Los_Angeles",
"end": "2012-09-01 09:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 09:30:00 America/Los_Angeles",
"end": "2012-09-01 10:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 10:00:00 America/Los_Angeles",
"end": "2012-09-01 10:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 10:30:00 America/Los_Angeles",
"end": "2012-09-01 11:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 11:00:00 America/Los_Angeles",
"end": "2012-09-01 11:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 11:30:00 America/Los_Angeles",
"end": "2012-09-01 12:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 12:00:00 America/Los_Angeles",
"end": "2012-09-01 12:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 12:30:00 America/Los_Angeles",
"end": "2012-09-01 13:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 13:00:00 America/Los_Angeles",
"end": "2012-09-01 13:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 13:30:00 America/Los_Angeles",
"end": "2012-09-01 14:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 14:00:00 America/Los_Angeles",
"end": "2012-09-01 14:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 14:30:00 America/Los_Angeles",
"end": "2012-09-01 15:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 15:00:00 America/Los_Angeles",
"end": "2012-09-01 15:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 15:30:00 America/Los_Angeles",
"end": "2012-09-01 16:00:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 16:00:00 America/Los_Angeles",
"end": "2012-09-01 16:30:00 America/Los_Angeles",
"span": 1
},
{
"isPending": false,
"isReservable": true,
"isReserved": false,
"label": " ",
"begin": "2012-09-01 16:30:00 America/Los_Angeles",
"end": "2012-09-01 17:00:00 America/Los_Angeles",
"span": 1
}
]
}
答案 0 :(得分:2)
看看这里:http://www.json.org/
基本上你有一个字典slots
里面有多个对象。键看起来像是2012-08-31 00:00:00 America/Los_Angeles
。这些键包含字典数组。
答案 1 :(得分:1)
你能做的最好的事情就是尝试一下!你会比在这里要求的时间少! 无论如何,你有:
- dictionary, with a "slot" key that has an associated value:
- dictionary, with a "2012-08-31 00:00:00 America/Los_Angeles" key that that has an associated value:
- array, containing objects:
- dictionary1
- dictionary2
- ....
因此,例如,要访问第二个元素的isPending属性:
[[[[dict objectForKey:@"slot"] objectForKey:@"2012-08-31 00:00:00 America/Los_Angeles"] objectAtIndex:1] valueForKey:@"isPending"];
答案 2 :(得分:0)
字典周围的[
和]
似乎表明它是一系列字典。
或者更确切地说,Array
位于Dictionary
内的Dictionary
内。第一段只涉及最里面的结构。
答案 3 :(得分:0)
您可能会发现在此处使用NSLog进行调试很有用。
假设你想知道你的班级是NSArray,Dictionary还是其他班级。一旦传递了JSON数据。要查看您的回复,请将其注销。
[NSLog(@" JSON data is kind of class %@", [NSStringFromClass([jsonData Class]);
这将告诉你json数据是什么类。
您也可以使用相同的方法来确定下一个项目是字典还是像这样的数组
[NSLog(@" JSON data is kind of class %@", [NSStringFromClass([[jsonData objectAtIndex:i]Class]);
但纯粹从观察中我会说你有一本词典数组词典词典
答案 4 :(得分:0)
我是这样做的。
for (NSString *slotKey in myslots.allKeys) {
NSDictionary *slot = [myslots valueForKey:slotKey];
NSArray *tests = [myslots objectForKey:slotKey];
for (NSDictionary *myDict in tests){
NSLog(@"%@", [myDict objectForKey:@"begin"]);
}
}