美文网首页
NSJSONSerialization dataWithJSON

NSJSONSerialization dataWithJSON

作者: 坤哥lqk | 来源:发表于2017-04-06 10:56 被阅读685次

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

    相关文章

      网友评论

          本文标题:NSJSONSerialization dataWithJSON

          本文链接:https://www.haomeiwen.com/subject/dxgfattx.html