Iphone 解析目标C中的纯JSON数组

Iphone 解析目标C中的纯JSON数组,iphone,ios,objective-c,xcode,json,Iphone,Ios,Objective C,Xcode,Json,我想解析一个简单的JSON数组,如: { "ns": [ [ "1364987475027", "Alert1", "001" ], [ "1364987475042", "Alert2", "001" ], [ "1364987475058"

我想解析一个简单的JSON数组,如:

{
    "ns": [
        [
            "1364987475027",
            "Alert1",
            "001"
        ],
        [
            "1364987475042",
            "Alert2",
            "001"
        ],
        [
            "1364987475058",
            "Alert4",
            "001"
        ]
    ]
}
以获取字符串的简单数组中的数组。我发现了很多关于JSON字典数组的帖子。但在本例中,JSON没有值的键。
请帮忙。

NSJSONSerialization方法
JSONObjectWithData:options:error
可以解决这个问题。您将得到一个字典,其中键“ns”有一个值,该值将是一个数组数组。

答案:

<代码> NSJSONSONLISTION < /Cord>类可用于将JSON转换为基础对象和基础对象到JSON。在你的情况下,你应该使用<代码> -jSnObjutsDebug:选项:<代码> NSJSONSur序化< <代码> >从给定的JSON数据中检索基础对象。


示例代码:

NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray *fetchedArr = [json objectForKey:@"ns"];

描述显示了你在寻找什么

   NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    NSArray *fetchedArr = [json objectForKey:@"ns"];

    for (NSArray *arr in fetchedArr) {
        [arr description];
    }

我想这会对你有帮助。

我提到过帖子是针对键控值的,而不是针对普通数组@JV42。你看过第一个链接的问题了吗?它包含了您问题的解决方案。
 NSError *error = NULL;
NSData* data = [yourJsonString dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary* json = [NSJSONSerialization
                                  JSONObjectWithData:data
                                  options:kNilOptions
                                  error:&error];
NSArray *resultArray = [json objectForKey:@"ns"];//resultArray contains array type objects...