Bittoo Bittoo - 6 months ago 24
Objective-C Question

How to parse jsonData?

Hi I'm working with ResponseData Response getting fine But while I'm parsing it is showing nil.first this is my Response

{
"type": "1",
"item": "Order created successfully.",
"order_id": "7"
}
{
"multicast_id": 9215180185089775977,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
"message_id": "0:1465191236656122%86acb02ff9fd7ecd"
}]
}


Here is my code

NSData * urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];


NSLog(@"Response code: %ld", (long)[response statusCode]);

NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Response ==> %@", responseData);

if (urlData)
{
jsonData=[[NSDictionary alloc] init];
jsonData = [NSJSONSerialization
JSONObjectWithData:urlData
options:NSJSONReadingMutableLeaves
error:nil];


How can I parse this kind of response?

Answer

Your json is incorrect

{
"type": "1",
"item": "Order created successfully.",
"order_id": "7"
} 
{
"multicast_id": 9215180185089775977,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [{
    "message_id": "0:1465191236656122%86acb02ff9fd7ecd"
  }]
}

for example, you forgot a comma/tag or close/open paranthesis are incorrect. Try to use this:

 {
    "type": "1",
    "item": "Order created successfully.",
    "order_id": "7",

    "multicast_id": 9215180185089775977,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [{
        "message_id": "0:1465191236656122%86acb02ff9fd7ecd"
      }]
    }