0

这是我的 php 页面中的 json。这是一个字典数组还是只是一个字典,里面有一个键和字典?我认为这是第二种选择,但我不确定,因为我得到了相互冲突的选择。一旦它在 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
            }
        ]
    }
4

5 回答 5

2

看看这里: http: //www.json.org/

基本上你有一个字典slots,里面有多个对象。键看起来是这样的东西2012-08-31 00:00:00 America/Los_Angeles。这些键包含字典数组。

于 2012-08-31T14:20:53.427 回答
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"];
于 2012-08-31T14:22:11.253 回答
0

The [ and ] around the dictionaries seems to suggest it's an array of dictionaries.

Or rather, an Array inside a Dictionary inside a Dictionary. The first paragraph only addresses the innermost structures.

于 2012-08-31T14:20:10.180 回答
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]);

但纯粹从观察来看,我会说你有一本字典数组字典

于 2012-08-31T14:30:34.843 回答
-1

这是我的做法。

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"]); 
    }
    }
于 2012-08-31T17:13:31.487 回答