[英]Parse JSON in Objective C
我有一個從cms返回的json,我需要將其分解並使用不同的值。
{"nodes":
[{"node":
{"created":"14012013165204","lastupdated":"03042013133901","type":"News"}
}]
}
我使用JSONKit框架,這是我的代碼:
NSString* theURL = [NSString stringWithFormat:@"http://testserver.com/content_lastupdate.json"];
NSError* err = nil;
NSURLResponse* response = nil;
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
NSURL*URL = [NSURL URLWithString:theURL];
[request setURL:URL];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:30];
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *resultsDictionary = [output objectFromJSONString];
NSLog([NSString stringWithFormat:(@"Response: %@"), output]);
NSDictionary *nodes = [resultsDictionary objectForKey:@"nodes"];
NSObject *node = [nodes objectForKey:@"node"];
我不知道如何獲得結果的下一部分。 找到了節點密鑰,但沒有找到下一個。 知道我在這里缺少哪些基本知識嗎?
“節點”是一個數組。 試試這個:
NSArray *nodes = resultsDictionary[@"nodes"];
NSDictionary *node = nodes[0];
node = node[@"node"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.