json test

NSString * filePath = @"/Users/user/xserver/TestJson/data.json";
NSString *jsonStr = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];


SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *json = [parser objectWithString:jsonStr error:nil];



NSDictionary *one = [json objectForKey:@"one"];
NSString *oneTitle = [one objectForKey:@"title"];

NSDictionary *two = [one objectForKey:@"two"];
NSString *twoTitle = [two objectForKey:@"title"];

NSArray *six = [[[[two objectForKey:@"Three"] 
						   objectForKey: @"Four"] 
						  objectForKey: @"Five"] 
						 objectForKey: @"Six"];

NSLog(@"Glossary Title: %@", oneTitle);
NSLog(@"GlossDiv Title: %@", twoTitle);

NSLog(@"GlossSeeAlso item 1: %@", [six objectAtIndex:0]);
NSLog(@"GlossSeeAlso item 2: %@", [six objectAtIndex:1]);

http://pro.ctlok.com/2010/08/objective-c-json-object.html

你可能感兴趣的:(C++,c,json,C#,Objective-C)