I have an NSDictionary
(params) which contains the below data:
{
deviceType = iPhone;
ordersActionList = ({
endDate = "07/14/2014 14:32";
orderId = 2807171;
reason = "Some reason";
}
);
}
When I parse the above using NSJSONSerialization
:
NSError *err;
NSData *jsonData =[NSJSONSerialization dataWithJSONObject:params options:0 error:&err];
It adds escape characters to endDate, the endDate shows up as below:
`"endDate": "07\/14\/2014 14:32"`
This is incorrect, can someone suggest how I can avoid escape characters in JSON when serializing using NSJSONSerialization
?
EDIT: This is my work around for now but I don't like doing this, I was hoping for a better solution:
-(NSData*) converToNSData:(NSDictionary *)params
{
NSError * err;
NSData *jsonData =[NSJSONSerialization dataWithJSONObject:params options:0 error:&err];
NSString *jsonStr1 = [NSString stringWithUTF8String:[jsonData bytes]];
jsonStr1 = [jsonStr1 stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
NSData *jsonData2 =[jsonStr1 dataUsingEncoding:NSUTF8StringEncoding];
return jsonData2;
}