iPhone/iOS JSON解析教程

Cas*_*ynn 103 iphone json objective-c uitableview ios

作为一种学习体验,我想创建一个调用webserver/webservice的iPhone应用程序,检索JSON响应,并使用该响应填充a的行UITableView(假设它将JSON转换为NSArray第一个).

有人知道任何可能有用的东西吗?

Tod*_*son 164

你会喜欢这个框架.

你会喜欢这个工具.

要了解JSON,您可能会喜欢这个资源.

你可能会喜欢这个教程.

  • 是的,那个项目搬到了github.在此处获取:https://github.com/stig/json-framework/. (2认同)

dar*_*inm 57

从iOS 5.0开始,Apple提供了NSJSONSerialization类 "将JSON转换为Foundation对象并将Foundation对象转换为JSON".没有外部框架可以合并,并且根据基准测试,它的性能非常好,明显优于SBJSON.

  • 因为它现在是2012年,iOS6即将来临 - 更有可能出现这种情况. (18认同)

cha*_*ika 6

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)