How can I get the JSON array data from nsstring or byte in xcode 4.2?

Posted by user1471568 on Stack Overflow See other posts from Stack Overflow or by user1471568
Published on 2012-06-21T09:03:48Z Indexed on 2012/06/21 9:16 UTC
Read the original article Hit count: 155

Filed under:
|
|

I'm trying to get values from nsdata class and doesn't work.

here is my JSON data.

{
    "count": 3,
    "item": [{
        "id": "1",
        "latitude": "37.556811",
        "longitude": "126.922015",
        "imgUrl": "http://175.211.62.15/sample_res/1.jpg",
        "found": false
    }, {
        "id": "3",
        "latitude": "37.556203",
        "longitude": "126.922629",
        "imgUrl": "http://175.211.62.15/sample_res/3.jpg",
        "found": false
    }, {
        "id": "2",
        "latitude": "37.556985",
        "longitude": "126.92286",
        "imgUrl": "http://175.211.62.15/sample_res/2.jpg",
        "found": false
    }]
}

and here is my code

-(NSDictionary *)getDataFromItemList
{

    NSData *dataBody = [[NSData alloc] initWithBytes:buffer length:sizeof(buffer)]; 
    NSDictionary *iTem = [[NSDictionary alloc]init];
    iTem = [NSJSONSerialization JSONObjectWithData:dataBody options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"id = %@",[iTem objectForKey:@"id"]);

    //for Test
    output = [[NSString alloc] initWithBytes:buffer length:rangeHeader.length encoding:NSUTF8StringEncoding];
    NSLog(@"%@",output);
    return iTem;

}

how can I access every value in the JSON? Please help me.

© Stack Overflow or respective owner

Related posts about ios

Related posts about xcode