Cas*_*ynn 103 iphone json objective-c uitableview ios
作为一种学习体验,我想创建一个调用webserver/webservice的iPhone应用程序,检索JSON响应,并使用该响应填充a的行UITableView(假设它将JSON转换为NSArray第一个).
有人知道任何可能有用的东西吗?
dar*_*inm 57
从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:@""]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
136834 次 |
| 最近记录: |