开发者

how to split JSON response into three different arrays

This is my JSON data:

开发者_运维知识库{
    "SearchList": [
        {
            "HeadLines NewsIds ": [
                "1056305",
                "1285209",
                "3248204"
            ],
            "NewsText NewsIds ": [
                "12328475",
                "12328324",
                "12328310",
                "12325544"
            ],
            "Issuers News Ids": [
                "4269",
                "21636",
                "21828",
                "22061"
            ]
        }
    ]
}

From this jason formate i need to store headlines new ids newstext newsids issuers news ids

Into three different array.....


Install JSONKit and use this code:

+(NSDictionary*) parseJson:(NSString*) jsonString {     
    NSDictionary *rootDict = nil;
    NSError *error = nil;
    @try {
        JKParseOptionFlags options = JKParseOptionComments | JKParseOptionUnicodeNewlines;
        rootDict = [jsonString objectFromJSONStringWithParseOptions:options error:&error];
        if (!rootDict) {
            NSLog(@"%@",[error localizedDescription]);
        }
    } @catch (NSException * e) {
        NSLog(@"%@ %@", [e name], [e reason]);
        rootDict = nil;
    }
    return rootDict;
}

Then iterate the resulting NSDictionary like this:

 NSDictionary *root = [Yourclass parseJson:string];
 NSDictionary *elements = [[root objectForKey:@"SearchList"] lastObject];
 NSArray *headlines = [elements objectForKey:@"HeadLines NewsIds"];
 // ...


- (void)interceptUrlRequest1:(NSString*)urlString withString:(NSString*)string {
    FavouriteData *favData=[[SharedObjects sharedInstance] favouriteData];
    NSRange match = [urlString rangeOfString:string];
if ([string isEqualToString:@"search.htm"]) {
    if (match.location!=NSNotFound) {
        NSString *url=[NSString stringWithString:@"url............"];
        NSData *data1=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
        NSString *response=[[NSString alloc]initWithData:data1 encoding:nil];

        SBJsonParser *parser=[SBJsonParser new];


        NSDictionary *root = [Webview parser:string];
        NSDictionary *elements = [[root objectForKey:@"SearchList"] lastObject];
        NSArray *headlines = [elements objectForKey:@"HeadLinesNewsIds"];
                NSArray *newstext=[element objectForKey:@"NewsTextNewsIds"];
                NSArray *issuersnews=[element objectForKey:@"IssuersNewsIds"];

My Class is Webview.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜