目前我有一个 JSON 对象,但是当我解析 VALUES 中的 startLabel 键配对元素时,我返回一个 nsdictionary,其中第一个元素为 NULL,其键为值。
这是 JSON 对象
(
{
values = (
{
start = 1370066400;
startLabel = 20130601000000;
value = "1.000000047497";
},
{
start = 1370067300;
startLabel = 20130601001500;
value = "1.000000047497";
},
{
start = 1370068200;
startLabel = 20130601003000;
value = "1.000000047497";
}
);
}
)
目前,这是字典对象“dict”的 NSLog 输出
(
"<null>",
(
20130601000000,
20130601001500,
20130601003000,
20130601004500,
20130601010000,
20130601011500,
20130601013000,
20130601014500,
20130601020000,
20130601021500,
20130601023000,
20130601024500,
20130601030000,
20130601031500,
20130601033000,
20130601034500,
20130601040000,
20130601041500,
20130601043000,
20130601044500,
20130601050000,
20130601051500,
20130601053000,
20130601054500,
20130601060000,
20130601061500,
20130601063000,
20130601064500,
20130601070000,
20130601071500,
20130601073000,
20130601074500,
20130601080000,
20130601081500,
20130601083000,
20130601084500,
20130601090000,
20130601091500,
20130601093000,
20130601094500,
20130601100000,
20130601101500,
20130601103000,
20130601104500,
20130601110000,
20130601111500,
20130601113000,
20130601114500,
20130601120000,
20130601121500,
20130601123000,
20130601124500,
20130601130000,
20130601131500,
20130601133000,
20130601134500,
20130601140000,
20130601141500,
20130601143000,
20130601144500,
20130601150000,
20130601151500,
20130601153000,
20130601154500,
20130601160000,
20130601161500,
20130601163000,
20130601164500,
20130601170000,
20130601171500,
20130601173000,
20130601174500,
20130601180000,
20130601181500,
20130601183000,
20130601184500,
20130601190000,
20130601191500,
20130601193000,
20130601194500,
20130601200000,
20130601201500,
20130601203000,
20130601204500,
20130601210000,
20130601211500,
20130601213000,
20130601214500,
20130601220000,
20130601221500,
20130601223000,
20130601224500,
20130601230000,
20130601231500,
20130601233000,
20130601234500
)
)
如何获取不包含 null 作为第一个 Key 的字典对象?
这是我使用的代码:
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray* data = [json objectForKey:@"fields"];
NSDictionary *graphStartDate = [data valueForKeyPath:@"values.startLabel"];
如果需要更多代码,请询问:) 但基本上就是这样。