标签:utf8 去掉空格 sub ret nsarray substring 系统 sda gen
//dic 转json 如果用系统自带的会出现空格。 + (NSString *)returnJSONStringWithDictionary:(NSDictionary *)dictionary{ //系统自带 // NSError * error; // NSData * jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:kNilOptions error:&error]; // NSString * jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; //自定义 NSString *jsonStr = @"{"; NSArray * keys = [dictionary allKeys]; for (NSString * key in keys) { jsonStr = [NSString stringWithFormat:@"%@\"%@\":\"%@\",",jsonStr,key,[dictionary objectForKey:key]]; } jsonStr = [NSString stringWithFormat:@"%@%@",[jsonStr substringWithRange:NSMakeRange(0, jsonStr.length-1)],@"}"]; return jsonStr; }
iOS NSDictionary 转Json 去掉换行去掉空格
标签:utf8 去掉空格 sub ret nsarray substring 系统 sda gen
原文地址:http://www.cnblogs.com/qingjoin/p/7521675.html