首页 > 代码库 > NSArray转json字符串

NSArray转json字符串

func arrayToJson(arr:NSArray) -> String {

    let jsonData: NSData = http://www.mamicode.com/try! NSJSONSerialization.dataWithJSONObject(arr, options: NSJSONWritingOptions.PrettyPrinted)

    let str:String = String(data: jsonData, encoding: NSUTF8StringEncoding)!

    return str

}

 

NSArray转json字符串