无法获取字符串 iphone 中的解析值
当我在控制台中执行此代码时..
NSMutableArray *feed2 =(NSMutableArray *) [facebook_response objectForKey:@"paging"];
我得到...
{
next = "https://graph.facebook.com/xyz/posts?limit=15&&until=1305300725";
previous = "https://graph.facebook.com/xyz/posts?limit=15&&since=1307032141";
}
现在
我试图将其放入数组中,并从中尝试将其放入字符串中...
就像这样
for (i=1; i<[feed2 count]; i++){
NSString* pagString=[[feed2 objectAtIndex:i]
NSString* myPaging=[pagString valueForKey:@"next"];
}
但是它正在崩溃这一点..
谁能告诉我该怎么办?
when I am executig this code ..
NSMutableArray *feed2 =(NSMutableArray *) [facebook_response objectForKey:@"paging"];
in console I am getting ...
{
next = "https://graph.facebook.com/xyz/posts?limit=15&&until=1305300725";
previous = "https://graph.facebook.com/xyz/posts?limit=15&&since=1307032141";
}
Now
I am trying to take it in the array and from that I am trying to take it in the string...
like this
for (i=1; i<[feed2 count]; i++){
NSString* pagString=[[feed2 objectAtIndex:i]
NSString* myPaging=[pagString valueForKey:@"next"];
}
however it is creshing at the this point..
can anyone tell me what to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要澄清问题中的几件事,例如您想要做什么以及您正在解析什么(我假设是 JSON)。
您还应该指定崩溃日志的内容(我假设是ArrayIndexOutOfBoundsException)。
之所以如此,是因为 feed2 不是一个数组,不应该被读取为一个数组(我可以通过查看你的 JSON 来判断)。它不包含任何对象,因此尝试访问索引 0 处的第一个对象(就像您尝试使用
objectAtIndex:
所做的那样)将导致崩溃。创建 feed2 使用:
在本例中,它包含键值对,因此您只需要以下内容即可获取所需的字符串:
You need to clarify several things in your question such as what you're trying to do, and what you're parsing (JSON I'm assuming).
You should also specify what the crash log says (which I'm assuming is an ArrayIndexOutOfBoundsException).
This is so because feed2 is not an array and should not be read as an array (which I can tell looking ar your JSON). It contains no objects so trying to access the first object at index 0 like you're trying to do with
objectAtIndex:
, will cause a crash.Create feed2 using:
In this case it contains key-value pairs so you need only the following to get the string you want: