///数组或者字典解析为json字符串
func toJSONString(dict:NSDictionary!)->NSString{
let data = try? NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions.PrettyPrinted)
let strJson = NSString(data: data!, encoding: NSUTF8StringEncoding)
return strJson!
}
代码示例:
let dic = ["method":"SignUp.getAuthKey","version":"V1.0.0","loginNo":["18708133592","13880****62","76****7"]]
let jsonDic = toJSONString(dic);
print("jsonString=\(jsonDic)");
///结果
jsonString={
"method" : "SignUp.getAuthKey",
"loginNo" : [
"18708133592",
"13880****62",
"76****7"
],
"version" : "V1.0.0"
}
网友评论