如何从JSON API格式字符串中提取特定类型的属性?我使用NSJSONSerialization
- 但它提取属性并将其放在included.attributes
..."included":[{"id":"","type":"name1","attributes":{...}},{"id":"","type":"form-data","attributes":{..}}]}
序列化为:
included = (
{
attributes = {..};id = "";
type = "name1";
},
{
attributes = {...};
id = "";
type = "name2";
}
);
}
有没有办法根据类型的值提取属性值?
答案 0 :(得分:1)
我使用以下代码来提取我需要的内容:
for (NSMutableArray* oneRow in attributes) {
if([[oneRow valueForKey:@"type"] isEqualToString:@"name"]){
formAttribute = [oneRow valueForKey:@"attributes"];
}
}
我原本希望找到一种可以做到这一点的方法或预定义函数 - 如果有的话,希望你把它添加为答案。