iPhone/iOS JSON 解析教程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5813077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:43:59  来源:igfitidea点击:

iPhone/iOS JSON parsing tutorial

iphoneobjective-ciosjsonuitableview

提问by Casey Flynn

As a learning experience, I want to make an iPhone application that calls a webserver/webservice, retrieves a JSON response, and uses that response to populate the rows of a UITableView(assuming it converts the JSON into an NSArrayfirst).

作为学习经验,我想制作一个 iPhone 应用程序,它调用一个网络服务器/网络服务,检索一个 JSON 响应,并使用该响应来填充 a 的行UITableView(假设它将 JSON 转换为NSArray第一个)。

Anyone know of anything that might be useful?

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

回答by Todd Hopkinson

You will love this framework.

你会喜欢这个框架

And you will love this tool.

你会喜欢这个工具的

For learning about JSON you might like this resource.

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

And you'll probably love this tutorial.

您可能会喜欢本教程

回答by darrinm

As of iOS 5.0 Apple provides the NSJSONSerialization class"to convert JSON to Foundation objects and convert Foundation objects to JSON". No external frameworks to incorporate and according to benchmarksits performance is quite good, significantly better than SBJSON.

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

回答by chandrika

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:@""]];
    }

回答by cloudsurfin

This is the tutorial I used to get to darrinm's answer. It's updated for ios5/6 and really easy. When I'm popular enough I'll delete this and add it as a comment to his answer.

这是我用来获得 darrinm 答案的教程。它已针对 ios5/6 进行了更新,非常简单。当我足够受欢迎时,我会删除它并将其作为评论添加到他的答案中。

http://www.raywenderlich.com/5492/working-with-json-in-ios-5

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://www.touch-code-magazine.com/tutorial-fetch-and-parse-json-in-ios6/

回答by Hiren

try out with this fastest JSON framework JSONKit. it's faster than normal JSON framework.

试试这个最快的 JSON 框架JSONKit。它比普通的 JSON 框架更快。

回答by Mike Gledhill

Here's a link to my tutorial, which walks you through :

这是我的教程的链接,它将引导您完成:

  • creating a JSON WCF Web Service from scratch (and the problems you'll want to avoid)
  • adapting it to read/write SQL Serverdata
  • getting an iOS 6 app to use the JSON servies.
  • using the JSON web services with JavaScript
  • 从头开始创建 JSON WCF Web 服务(以及您希望避免的问题)
  • 使其适应读/写SQL Server数据
  • 获取 iOS 6 应用程序以使用 JSON 服务。
  • 将 JSON Web 服务与 JavaScript 结合使用

http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm

http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm

All source code is provided, free of charge. Enjoy.

免费提供所有源代码。享受。