从JSON API中提取特定类型的属性

时间:2015-09-01 05:42:44

标签: ios json json-api

如何从JSON API格式字符串中提取特定类型的属性?我使用NSJSONSerialization - 但它提取属性并将其放在included.attributes

..."included":[{"id":"","type":"name1","attributes":{...}},{"id":"","type":"form-data","attributes":{..}}]}

序列化为:

included =     (
            {
        attributes =             {..};id = "";
        type = "name1";
    },
            {
        attributes =             {...};
        id = "";
        type = "name2";
    }
);
}

有没有办法根据类型的值提取属性值?

1 个答案:

答案 0 :(得分:1)

我使用以下代码来提取我需要的内容:

    for (NSMutableArray* oneRow in attributes) {
    if([[oneRow valueForKey:@"type"] isEqualToString:@"name"]){
        formAttribute = [oneRow valueForKey:@"attributes"];
    }
}

我原本希望找到一种可以做到这一点的方法或预定义函数 - 如果有的话,希望你把它添加为答案。