无法获取字符串 iphone 中的解析值

发布于 2024-11-13 06:19:02 字数 625 浏览 4 评论 0原文

当我在控制台中执行此代码时..

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 技术交流群。

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

发布评论

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

评论(1

谷夏 2024-11-20 06:19:02

您需要澄清问题中的几件事,例如您想要做什么以及您正在解析什么(我假设是 JSON)。

您还应该指定崩溃日志的内容(我假设是ArrayIndexOutOfBoundsException)。

之所以如此,是因为 feed2 不是一个数组,不应该被读取为一个数组(我可以通过查看你的 JSON 来判断)。它不包含任何对象,因此尝试访问索引 0 处的第一个对象(就像您尝试使用 objectAtIndex: 所做的那样)将导致崩溃。

创建 feed2 使用:

NSDictionary *feed2 = (NSDictionary *)[facebook_response objectForKey:@"paging"];

在本例中,它包含键值对,因此您只需要以下内容即可获取所需的字符串:

NSString *myPaging = (NSString *)[feed2 valueForKey:@"next"];

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:

NSDictionary *feed2 = (NSDictionary *)[facebook_response objectForKey:@"paging"];

In this case it contains key-value pairs so you need only the following to get the string you want:

NSString *myPaging = (NSString *)[feed2 valueForKey:@"next"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文