1

I have an NSString that looks like:

{
   "name": "anEvent",
      "args": [
      {
        "ct": "Un",
        "someUUID": "D7EC06DE-98D3-436F-A657-FB043567FB67",
        "userName": "Joe Smith",
        "long": "-139.724302",
        "lat": "39.402768"
    }
  ]
}

How can I get just the inner part

{
    "ct": "Un",
    "someUUID": "D7EC06DE-98D3-436F-A657-FB04383CFB67",
    "userName": "Joe Smith",
    "long": "-139.724305",
    "lat": "39.402768"
}

into an NSDictionary?

Thanks.

Mani
  • 17,549
  • 13
  • 79
  • 100
bhartsb
  • 1,316
  • 14
  • 39

2 Answers2

5

Deserialise the whole string, then use objectForKey:@"args" to drill in to the part you want.

Wain
  • 118,658
  • 15
  • 128
  • 151
3

Try with this code:

 NSDictionary *dictObj = [NSJSONSerialization JSONObjectWithData:[yourString dataUsingEncoding:NSUTF8StringEncoding]
                                                         options:NSJSONReadingMutableContainers
                                                           error:nil];
 NSDictionary *requiredObject = [[dictObj objectForKey:@"args"] objectAtIndex:0];
Apurv
  • 17,116
  • 8
  • 51
  • 67
  • essentially what is given but with slight differences: NSError *error; NSDictionary *d = [NSJSONSerialization JSONObjectWithData:[yourString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error]; – bhartsb Apr 26 '14 at 09:41