怎么去掉字典转json字符串的时间,空格换行的问题
in my method, I need to call a web service. I have used the following
[NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&parseError]
where jsonDictionary is
{
"timeStamp" : "",
"listOfScratchNotes" : [
{
"id" : "13",
"location" : "reqw",
"dateOfMeeting" : "23/12/2012",
"dealers" : "fr"
}
]
}
after using the dataWithJSONObject: method, my dateOfMeeting: gets converted to 23\/12\/2012
How can I avoid this?
Please help.
ios objective-c web-services
shareimprove this question
asked Jun 3 '15 at 11:17
Shradha
4331724
add a comment
1 Answer
active oldest votes
up vote
1
down vote
accepted
Try this:
NSDictionary *dict = // Dictionary here..
NSData *dataRecvd = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:&error];
if(!dataRecvd && error){
NSLog(@"Error creating JSON: %@", [error localizedDescription]);
return;
}
//NSJSONSerialization converts a URL string from http://... to http:\/\/... remove the extra escapes
Str = [[NSString alloc] initWithData:dataRecvd encoding:NSUTF8StringEncoding];
Str = [Str stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
dataRecvd = [policyStr dataUsingEncoding:NSUTF8StringEncoding];
shareimprove this answer