-3

I want to parse a plain JSON array like:

{
    "ns": [
        [
            "1364987475027",
            "Alert1",
            "001"
        ],
        [
            "1364987475042",
            "Alert2",
            "001"
        ],
        [
            "1364987475058",
            "Alert4",
            "001"
        ]
    ]
}

To get the array in simple arrays of string. I found many posts with JSON dictionary arrays. But in this case the JSON is not having keys for the values. Kindly help.

2
  • I mentioned that the posts are for keyed values and not for plain arrays @jv42 Commented Apr 3, 2013 at 12:41
  • Have you looked at the first question linked? It contains a solution to your problem. Commented Apr 3, 2013 at 13:16

4 Answers 4

17

Answer : NSJSONSerialization.

NSJSONSerialization class can be used to convert JSON to Foundation objects and Foundation objects to JSON. In your case, you should use -JSONObjectWithData:options:error: of NSJSONSerialization class to retrieve a Foundation object from given JSON data.


Sample Code :

NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray *fetchedArr = [json objectForKey:@"ns"];
Sign up to request clarification or add additional context in comments.

Comments

2

The NSJSONSerialization method JSONObjectWithData:options:error can to that. You will get a dictionary with one value for the key "ns" and the value will be an array of arrays.

Comments

2
 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...

I think it will be helpful to you.

Comments

2

And the description shows what you are looking for

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

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.