2015-06-03 78 views
0

在我的方法中,我需要調用一個Web服務。我已經使用了以下NSJSONSerialization dataWithJSONObject:options:NSJSONWritingPrettyPrinted error:method extra extra「/」

[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

試試這個:

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