iphone - SBJson 解析尝试—— Objective-C

标签 iphone objective-c ios ipad sbjson

我正在尝试解析以下 JSON(我认为上次检查时已验证):

{
    "top_level" =     (
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object1";
        },
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object2";
        },
                {
            "download" = "http:/target.com/some.zip";
            "other_information" = "other info";
            "notes" =             (
                                {
                    obj1 = "some text";
                    obj2 = "more notes";
                    obj3 = "some more text still";
                }
            );
            title = "name_of_object3";
        }
    );
}

我的尝试是使用以下内容:

NSDictionary *myParsedJson = [myRawJson JSONValue];

for(id key in myParsedJson) {
    NSString *value = [myParsedJson objectForKey:key];
    NSLog(value);
}

错误:

-[__NSArrayM length]: unrecognized selector sent to instance 0x6bb7b40

问题: 在我看来,JSon 值使 myParsedJson 对象成为 NSArray 而不是 NSDictionary。

我如何遍历名为 name_of_object 的对象并访问每个嵌套字典?我的做法是否正确?

最佳答案

NSLog 的第一个参数必须是一个字符串。试试这个:

NSLog(@"%@", value);

关于iphone - SBJson 解析尝试—— Objective-C ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12700527/

相关文章:

ios - 在初始化 PhoneGap 之前显示 ViewController

iphone - 更改 UIScrollView 的背景颜色?

iphone - Core Data 可以使用 Web 服务作为持久性存储吗?

iphone - 部分用户的UILocalNotification音量较低,有什么方法可以控制吗?

iphone - 有没有用于视频 session 的 iPhone 插件?就像面对面插件一样?

iphone - 多个 ViewController、xib 文件位于一个 Storyboard 中

ios - 底部 5 行的 UITableView 背景颜色

iphone - UITableView didSelectRowAtIndexPath : Not Working

ios - UIWebView objectivists-c 使用 webkit 在 vi​​ewdidload 上显示折旧

objective-c - 在 NS_OPTIONS 中测试多个标志或条件