先去掉转移符/
NSMutableString *responseString = @"{\"cate\":\"2\",\"share_url\":\"http://api.fafaasfaijia.com/fd/notifdce_detail.html?notisdssdsce_id=18&\",\"id\":\"18\"}";
NSString *character = nil;
for (int i = 0; i < responseString.length; i ++) {
character = [responseString substringWithRange:NSMakeRange(i, 1)];
if ([character isEqualToString:@"\\"])
[responseString deleteCharactersInRange:NSMakeRange(i, 1)];
}
NSLog(@"%@",responseString);
将JSON字符串转化为字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
if (jsonString == nil) {
return nil;
}
NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",dic);
将字典串转化为JSON字符串
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSJSONWritingPrettyPrinted 是有换位符的。
如果NSJSONWritingPrettyPrinted 是nil 的话 返回的数据是没有 换位符的