NSJSONSerialization dataWithJSONObject: options:NSJSONWritingPrettyPrinted error: method adding extra “/”

怎么去掉字典转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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容