我有一个json数组,我正在尝试从中提取数据。该数组是使用NSJSONSerialization创建的。这是json数组从NSLog看起来的样子([jsonArray debugDescription]);:
{
properties = (
{
ID = 12345;
PropertyName = "McDonalds";
key = 00112233445566778899aabbccddeeff;
},
{
ID = 12346;
PropertyName = "Taco Bell";
key = 00112233445566778899aabbccddeef0;
},
{
ID = 12347;
PropertyName = "Burger King";
key = 00112233445566778899aabbccddeef1;
}
);
success = 1;
totalCount = 3;
}
我需要提取每个ID和每个Property name,并将值转储到单独的数组中。我怎么能这样做?
答案 0 :(得分:3)
您可以使用键值编码:
NSArray *ids = [jsonArray valueForKeyPath:@"properties.ID"];
NSArray *propertyNames = [jsonArray valueForKeyPath:@"properties.PropertyName"];