Reputation: 161
I am trying to decode a json string with either jsonkit or nsjsonserialization from a server but I am getting the colon : marks changed to equal = signs and commas , changed to semi-colons ; e.g. from server:
"response": { "status": "OK","message": "","timestamp": "30 Mar 2013 11:33:08",
"url":"/abc/api/getconfig/dev-game?language=en" }...
but the response I get doing either:
JSONDecoder *decodedData = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionStrict];
NSDictionary *parsedList = [decodedData objectWithData:responseData];
or:
NSError *jsonError = nil;
NSDictionary *parsedList = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&jsonError];
gives me:
response = {
message = "";
status = OK;
timestamp = "30 Mar 2013 11:33:08";
url = "/abc/api/getconfig/dev-game?language=en";
};
result = {
meta = {
dateLastModified = "29 Mar 2013 11:59:17";
};
which gives me a lot of problems while trying to parse. I can do:
NSSTring *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
or put the request url in a browser or jsonlint.com and I get the proper formatting, but I need this in a dictionary, because I need to be able to parse it. Unless it will be better to put this into a different data type, because I will be trying to find specific keys i.e. get every "column" if I have column_1, column_2... Thanks in advance.
Upvotes: 1
Views: 2339
Reputation: 5543
JSONKit
and NSJSONSerialization
will parse the JSON string for you and create the NSDictionary
/NSArray
/NSString
/NSNumber
objects for you. You don't have to parse anything yourself. You're seeing equal signs and such because you're printing a description of the parsed response object (probably using NSLog
).
Upvotes: 1