user836026
user836026

Reputation: 11340

How to parse JSON response

I wonder how could I parse JSON in iOS. notice I tried to use:

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

however, i give me the following error:

"The operation couldn’t be completed. (Cocoa error 3840.)" (Badly formed object around character 310.) UserInfo=0x135460 {NSDebugDescription=Badly formed object around character 310.}

The JSON response I'm trying to parse is:

{"error":0,"token":"59188a107d705f8c51585d719769e0642ce98b79d86fdace30dbc58efba301cc","status":"200","messages":[{"update_time":2012-03-09 12:25:26.0,"seq":"21","lng":58.4236,"msg":"Bill We-Mark : Test","lat":23.5871}],"error_msg":""}

There is No char 310 here???!!!!

Upvotes: 3

Views: 5900

Answers (2)

sch
sch

Reputation: 27506

character 310 means the character at index 310.

Any way, your problem is here "update_time":2012-03-09 12:25:26.0. You have to add quotes: "update_time":"2012-03-09 12:25:26.0"?

Upvotes: 10

QED
QED

Reputation: 9913

No offense, are you sure that's the string you're parsing? Also, I would put that date in quotes to see what happens. Best practice is to put all literal values in quotes. If you can't control the JSON, a stern email is in order.

Upvotes: 2

Related Questions