php - NSArray 无法识别我放入其中的内容并给我错误

标签 php iphone ios nsarray json

我正在使用 NSArray 并将我使用 json_encode 检索到的字符串放入其中 当它是纯文本时它可以工作,但如果它喜欢我的图像并给我这个错误则不工作

enter image description here

我也试过使用 NSMutableArray 但同样的问题,所以如果问题来自这些 "\r\n".. 等,如何将其转换为纯文本?

这是我使用的代码:

NSError *er;
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/ost.php"]];
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *json_string = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
    content = [parser objectWithString:json_string error:&er];
    NSLog(@"%@",json_string);     
NSLog(@"%d",[content count]);
    NSLog(@"%@",[content objectAtIndex:0]);

最佳答案

我看到一个 NSDictinoary 错误,它使用 objectForKey 而不是 objectAtIndex

您的问题可能是:

NSLog(@"%@",[content objectAtIndex:0]);

检查 content 的类型这可能是一个字典,被要求提供索引处的对象。

关于php - NSArray 无法识别我放入其中的内容并给我错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263642/

相关文章:

iphone - 尝试构建存档时尝试获取 Apple Mach-O 链接器错误

javascript - Famo.us 'Fastclick' 在手机上触发两次点击

ios - 如何在 Xcode 中为 iOS 应用程序添加 iPhone 5 大屏幕支持?

php - 如何从 Playstation Store 获取价格

PHPUnit 打印测试执行时间

iphone - iOS:从另一个 View 将新单元格添加到表格 View

ios - pod trunk - 使用不同/多个帐户推送到 repos

php - 从 mysql 数据库上传时,如何显示带有图像的最后 5 个帖子?

php - JSON 格式化额外字符

ios - 使用 KIF 以编程方式将点击事件发送到 iOS 中的后台坐标