1

How do I extract the attributes of a specific type from a JSON API format string? I used NSJSONSerialization- but that extracts the attributes and puts it under included.attributes

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

that serializes into:

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

is there a way to extract values of attribute based on value of type?

4

1 回答 1

1

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

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

我曾希望找到一种方法或预定义的函数可以做到这一点——如果有,希望你将其添加为答案。

于 2015-09-01T05:53:07.413 回答