美文网首页
Swift----02 数组与字符串互转

Swift----02 数组与字符串互转

作者: A慢慢懂 | 来源:发表于2021-04-20 17:36 被阅读0次

    在使用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: ",")
    

    相关文章

      网友评论

          本文标题:Swift----02 数组与字符串互转

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