问题描述
我想用超过500条评论来解析reddit帖子中的评论.例如以下示例: http://www.reddit.com/comments/xu11o json网址为: http://www.reddit.com/comments/xu11o.json
I want to parse the comments of a reddit post with over 500 comments.For example this one: http://www.reddit.com/comments/xu11oThe json url is: http://www.reddit.com/comments/xu11o.json
在使用SBJson实现这一目标.当我尝试使用此代码获取NSArray时:NSString* response = [request responseString];NSArray* responseArray = [response JSONValue];
In am using SBJson to achieve this.When I try to get a NSArray with this code:NSString* response = [request responseString];NSArray* responseArray = [response JSONValue];
我收到此错误消息:-JSONValue failed. Error is: Input depth exceeds max depth of 32
将深度更改为更大的数量(例如100)会使我的应用崩溃.
I get this error message: -JSONValue failed. Error is: Input depth exceeds max depth of 32
Changing the depth to a higher number of for example 100 makes my app crash.
如果reddit帖子中只有20条评论,我会得到NSArray并可以成功显示它们.
If the reddit post has only 20 comments I get the NSArray and can successfully display them.
要获得NSArray,我需要更改什么?
What do I have to change to get the NSArray?
推荐答案
您是否尝试过Apple的 NSJSONSerialization JSON解析库?可以.
Have you tried Apple's NSJSONSerialization JSON parsing library? It works.
NSString *urlString = @"http://www.reddit.com/comments/xu11o.json";
NSURL *url = [NSURL URLWithString:urlString];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:&response
error:&error];
id jsonObj = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
// Do something with jsonObj which is an array.
只需确保在发货前将下载代码切换为异步即可.
Just make sure you switch your download code to asynchronous before shipping.
最诚挚的问候.
这篇关于解析json-达到最大深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!