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

标签 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";
    }
);
}

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

最佳答案

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

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

我曾希望找到可以执行此操作的方法或预定义函数 - 如果有,希望您将其添加为答案。

关于ios - 从 JSON API 中提取特定类型的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32324292/

相关文章:

ios - 根据 plist 中的信息隐藏/显示按钮

ios - WKWebView 不尊重宽度=设备宽度

postgresql - 使用 PostgreSQL 和 json-api 的发布请求返回一个空体

ios - 尝试将数据从解析添加到 IOS 中的 NSMutableArray

json - 使用 JSON 数据,尝试解析嵌套数据

jquery - 任意对象成员选择 C++

Java - 根据两个属性值对 JSONArray 进行排序

ruby-on-rails - 使用 active_model_serializers 序列化模型数组

ember.js - 使用(现在默认)Ember Data JSON-API 适配器处理错误

ios - UITableView 更新后的 ReloadData