将此数据从JSON解析为NSDictionary

时间:2014-11-06 12:22:24

标签: ios objective-c json nsdictionary

我在将一些数据从JSON解析为NSDictionary时遇到了一些问题,JSON内部的数据遵循以下模式:

    object =     (
            {
        "field1" = 2;
        "field2" = "something";
        array =             {
            "field3" = "anotherThing";
            booleanField = true;
           {
            };
            otherThing = "yay";
        };    
            },
         {
        "field1" = 2;
        "field2" = "something";
        array =             {
            "field3" = "anotherThing";
            booleanField = true;
           {
            };
            otherThing = "yay";
        };    
            } )     

如何使用NSArray创建NSDictionaries

我希望我只是解释它

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

NSError *jsonParsingError = nil;
NSArray *contentArray = [NSJSONSerialization
                         JSONObjectWithData:[aContentString dataUsingEncoding:NSUTF8StringEncoding]
                         options:0
                         error:&jsonParsingError];  

希望它有所帮助。

答案 1 :(得分:-1)

可能重复(How to convert JSON serialized data to NSDictionary

如果您的回复是object = (...);

NSError *err;
NSDictionary *dictObject = [NSJSONSerialization JSONObjectWithData:yourData options:NSJSONReadingMutableContainers error:&err];
NSArray *arr = dictObject[@"object"];

如果您的回复是(...);

NSError *err;
NSArray *arrObject = [NSJSONSerialization JSONObjectWithData:yourData options:NSJSONReadingMutableContainers error:&err];

也许它会帮助你。