Swift----02 数组与字符串互转
2021-04-20 本文已影响0人
A慢慢懂
在使用swift5情况下
1、字典数组转字符串
//初始化数组
var searchFileds = [NSDictionary]()
//字典
let storeInfo =["operator":"eq","field":"store_code","value":"9999"]
//数组添加字典
searchFileds.append(storeInfo as NSDictionary)
//转换为NSdata类型
let data : NSData! = try? JSONSerialization.data(withJSONObject: searchFileds, options: []) as NSData?
//data类型转换成字符串
let JSONString = NSString(data:data as Data,encoding:String.Encoding.utf8.rawValue)
2、字符串数组转字符串
let someInt = ["1","2","3","4","5"]
let str = someInt.joined(separator: ",")