Answers:
从iOS 5.0开始,Apple提供了NSJSONSerialization类 “将JSON转换为Foundation对象并将Foundation对象转换为JSON”。没有外部框架可以合并,根据基准测试,它的性能相当好,明显优于SBJSON。
SBJSON *parser = [[SBJSON alloc] init];
NSString *url_str=[NSString stringWithFormat:@"Example APi Here"];
url_str = [url_str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url_str]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding]
NSDictionary *statuses = [parser2 objectWithString:json_string error:nil];
NSArray *news_array=[[statuses3 objectForKey:@"sold_list"] valueForKey:@"list"];
for(NSDictionary *news in news_array)
{
@try {
[title_arr addObject:[news valueForKey:@"gtitle"]]; //values Add to title array
}
@catch (NSException *exception) {
[title_arr addObject:[NSString stringWithFormat:@""]];
}
这是我用来获得darrinm答案的教程。它已针对ios5 / 6更新,非常简单。当我足够受欢迎时,我将其删除并将其添加为他的答案的注释。
http://www.raywenderlich.com/5492/working-with-json-in-ios-5
http://www.touch-code-magazine.com/tutorial-fetch-and-parse-json-in-ios6/
这是我的教程的链接,它指导您完成以下操作:
http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm
免费提供所有源代码。请享用。