Error on JSON parsing

kamlesh shingarakhiya

I'm having a problem on parsing a JSON. That is my code.

-(void)requstJson1:(ASIHTTPRequest *)request
{
    jsonResponse = [request responseString];
    jsonDic = [jsonResponse JSONValue];
    jsonResult = [[jsonDic valueForKey:@"events"] retain];
    type=[[jsonResult valueForKey:@"time"] retain];
    data=[[jsonResult valueForKey:@"data"] retain];
    NSDictionary *dic=[data JSONValue];
    hp=[[dic valueForKey:@"hp"] retain];
}

That is my JSON Response

{
    "result": "ok",
    "totalcount": 422,
    "events": [
        {
            "id": "52982168e4b00e53abdace66",
            "deviceId": "203",
            "channelId": "",
            "data": "{\"hp\":\"6586129568\",\"camID\":\"camID120\",\"device_id\":38,\"pairedDeviceId\":\"204\"}",
            "longitude": 103.82,
            "latitude": 1.352,
            "type": "event-intercom-visitor-alert",
            "time": "29/11/2013 05:09:54",
            "blobId": "",
            "messageCount": 0,
            "patchEventVideoURL": "",
            "deviceName": "Intercom"
        }
    ]
}

I get all the response but i am not getting this "{\"hp\":\"6586129568\",\"camID\":\"camID120\",\"device_id\":38,\"pairedDeviceId\":\"204\"}" And get error like this -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1c5cb310 2013-11-29 12:37:33.280 Intercom[14720:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1c5cb310' * First throw call stack: Thank you

kamlesh shingarakhiya

Sorry for that trouble the JSON is not properly formatted the correct example is :

{
    "result": "ok",
    "totalcount": 422,
    "events": [
        {
            "id": "52982168e4b00e53abdace66",
            "deviceId": "203",
            "channelId": "",
            "data": {\"hp\":\"6586129568\",\"camID\":\"camID120\",\"device_id\":38,\"pairedDeviceId\":\"204\"},
            "longitude": 103.82,
            "latitude": 1.352,
            "type": "event-intercom-visitor-alert",
            "time": "29/11/2013 05:09:54",
            "blobId": "",
            "messageCount": 0,
            "patchEventVideoURL": "",
            "deviceName": "Intercom"
        }
    ]
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related