Parsing Json to get all the contents in one NSArray

不羁岁月 提交于 2019-12-02 16:56:31

问题


That's the content...

[
    {
        "id": "",
        "title": "",
        "website": "",
        "categories": [
            {
                "id": "",
                "label": ""
            }
        ],
        "updated": 
    },
    {
        "id": "",
        "title": "",
        "website": "",
        "categories": [
            {
                "id": "",
                "label": ""
            }
        ],
        "updated": 
    }
]

How can I insert every feed source in one array?

 NSDictionary *results = [string JSONValue];
NSArray *subs = [results valueForKey:@"KEY"];

Which key I must insert? THanks


回答1:


as I can see your structure, you will get out of this JSON-String

NSArray:
[
    NSDictionary:
    {
        NSString: "id",
        NSString: "title",
        NSString: "website",
        NSArray:  "categories": 
        [
            NSDictionary:
            {
                NSString: "id",
                NSString: "label"
            }
        ],
        NSNumber: "updated"
    },
    NSDictionary:
    {
        ...
    }
]

So you have already an array of "Feeds" at root and you have to itterate them with their index in the array with. For first id i.e. [[myJsonStructure objectAtIndex:0] objectForKey:@"id"];



来源:https://stackoverflow.com/questions/17395136/parsing-json-to-get-all-the-contents-in-one-nsarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!