美文网首页
数组或者字典解析为json字符串

数组或者字典解析为json字符串

作者: JackMayx | 来源:发表于2016-06-07 11:15 被阅读69次
    ///数组或者字典解析为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"
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:数组或者字典解析为json字符串

          本文链接:https://www.haomeiwen.com/subject/cqmddttx.html