如何解析比 NSString 更长的 JSON 文件?

发布于 2024-09-29 05:11:57 字数 562 浏览 0 评论 0原文

我有点陷入一个项目中。 我正在编写一些代码来获取 JSON 文件并将其存储在 NSString 中,然后将其解析为 NSArray。

但我收到一个错误:

2010-10-27 20:59:44.813 GeraldKrvyn[21752:207] -JSONValue 失败。错误跟踪是:( “Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \“无法识别的前导字符\” UserInfo=0x7637890 {NSLocalizedDescription=无法识别的前导字符}”

我认为问题与 NSString 可以采用的有限值有关。

顺便说一句,这是我正在使用的提要: http://www.geraldkervyn.com/api/get_recent_posts/

将其解析为 NSArray 最方便的方法是什么?

谢谢 !

I'm a bit stuck in a project.
I was writing some code to get a JSON file and store it in an NSString before parsing it into a NSArray.

But I get an error:

2010-10-27 20:59:44.813 GeraldKervyn[21752:207] -JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x7637890 {NSLocalizedDescription=Unrecognised leading character}"

I think the problem is related to the limited value that an NSString can take.

BTW this is the feed I'm using : http://www.geraldkervyn.com/api/get_recent_posts/

What would be the most convenient way to parse this into an NSArray ?

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牛↙奶布丁 2024-10-06 05:11:57

首先,将 SBJson 代码添加到您的项目中(由 Stig Brautaset 提供)。然后这样做...

 NSString *subject = @"http://www.geraldkervyn.com/api/get_recent_posts/";
 NSString *encodedSubject = 
    [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 NSString *test = [NSString stringWithContentsOfURL:[NSURL URLWithString:encodedSubject]];
 SBJsonParser *parser = [[SBJsonParser new] autorelease];
 NSDictionary *json = [parser objectWithString:test];
 NSArray *values = [json objectForKey:@"posts"];

First, Add the SBJson code to your project, courtesy of Stig Brautaset. Then do this...

 NSString *subject = @"http://www.geraldkervyn.com/api/get_recent_posts/";
 NSString *encodedSubject = 
    [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 NSString *test = [NSString stringWithContentsOfURL:[NSURL URLWithString:encodedSubject]];
 SBJsonParser *parser = [[SBJsonParser new] autorelease];
 NSDictionary *json = [parser objectWithString:test];
 NSArray *values = [json objectForKey:@"posts"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文