[OsChina] ios把数组转化为json再转化为字符串、再去除空格和分隔符“\n”

发表于:  阅读量:11059

摘要

-(NSString*)pictureArrayToJSON:(NSArray*)picArr{?????????NSData*data=[NSJSONSerializationdataWithJSONObject:picArroptions:NSJSONWritingPrettyPrintederror:nil];??????...

- (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:@""];
    jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSLog(@"jsonStr==%@",jsonStr);
    return jsonStr;
}

 

渝ICP备16002246号 Copyright © 2017. Singee77.com