美文网首页
iOS开发数组转json字符串去掉转义字符

iOS开发数组转json字符串去掉转义字符

作者: Stephen_Huang | 来源:发表于2020-04-07 14:55 被阅读0次
    - (NSString *)pictureArrayToJSON:(NSArray *)picArr {
    
        NSData *data=[NSJSONSerialization dataWithJSONObject:picArr options:NSJSONWritingPrettyPrinted error:nil];
    
        NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
        //去除空格和回车:
        jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:[@""](https://my.oschina.net/u/2433434)];
        jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:[@""](https://my.oschina.net/u/2433434)];
        NSLog(@"jsonStr==%@",jsonStr);
        return jsonStr;
    }
    

    相关文章

      网友评论

          本文标题:iOS开发数组转json字符串去掉转义字符

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