I'm trying to parse JSON into NSDictionary. I have tried a lot of different ways and i always have the same error. Here's the simplest example:
NSString *response = [request responseString];
NSLog(@"%@",response);
NSDictionary *jsonDict = [response JSONValue];
NSLog(@"%@",jsonDict);
I can have two types of responseString:
1)something like {"s_login":{"error":6}}
and
2) something like {s_login:{"error":0,"sid":"66d4da3e870427bb"}}
So the problem is:
When responseString is 1 - everything is OK. I'm able to make it into NSDictionary and my NSLog tells me:
{
"s_login" = {
error = 6;
};
}
but when responseString is the second variant, then NSDictionary is null and this is what i'm having in console output:
-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object key string expected\" UserInfo=0x6043680 {NSLocalizedDescription=Object key string expected}"
Seems like i've described my issue fully. Any help is highly desired and appreciated. Thanks for your time
The response:
{s_login:{"error":0,"sid":"66d4da3e870427bb"}}
is not a valid JSON string. It's missing the double quotes around s_login
. They are mandatory.
You'll have to fix it on the server side.