NSJSONSerialization dataWithJSONObject:options:NSJSONWritingPrettyPrinted error:方法添加额外的“/”

时间:2015-06-03 11:17:57

标签: ios objective-c web-services

在我的方法中,我需要调用一个Web服务。我使用了以下

[NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&parseError]

其中jsonDictionary是

{
  "timeStamp" : "",
  "listOfScratchNotes" : [
    {
      "id" : "13",
      "location" : "reqw",
      "dateOfMeeting" : "23/12/2012",
      "dealers" : "fr"
    }
  ]
}

使用dataWithJSONObject:方法后,我的dateOfMeeting:转换为23\/12\/2012

我该如何避免这种情况?

请帮忙。

1 个答案:

答案 0 :(得分:1)

试试这个:

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];