【发布时间】:2011-08-14 08:38:21
【问题描述】:
作为学习经验,我想制作一个 iPhone 应用程序,它调用 webserver/webservice,检索 JSON 响应,并使用该响应填充 UITableView 的行(假设它将 JSON 转换为 @987654322 @先)。
有人知道什么有用的吗?
【问题讨论】:
标签: iphone objective-c ios json uitableview
作为学习经验,我想制作一个 iPhone 应用程序,它调用 webserver/webservice,检索 JSON 响应,并使用该响应填充 UITableView 的行(假设它将 JSON 转换为 @987654322 @先)。
有人知道什么有用的吗?
【问题讨论】:
标签: iphone objective-c ios json uitableview
【讨论】:
从 iOS 5.0 开始,Apple 提供了 NSJSONSerialization class“将 JSON 转换为 Foundation 对象并将 Foundation 对象转换为 JSON”。无需合并外部框架,根据benchmarks,它的性能相当不错,明显优于 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:@""]];
}
【讨论】:
试试这个最快的 JSON 框架JSONKit。它比普通的 JSON 框架更快。
【讨论】:
这是我用来回答 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
所有源代码均免费提供。享受吧。
【讨论】: