json转base64格式
letoriginStr :String= jsM.yy_modelToJSONString() ??""
letoriginData:NSData= originStr.data(using:String.Encoding.utf8)!asNSData
letencodeResult:String= originData.base64EncodedString(options: .endLineWithLineFeed)
print(encodeResult)
解码base64为json
letdecodeData:NSData=NSData(base64Encoded: encodeResult, options:NSData.Base64DecodingOptions(rawValue:NSData.Base64DecodingOptions.RawValue(0)))!
letdecodeStr:String=NSString(data: decodeDataasData, encoding:String.Encoding.ascii.rawValue)!asString
print(decodeStr)
网友评论