Reputation: 4008
My application's network request is encoded.
In Objective-C
NSData *encodeData = [str dataUsingEncoding:NSUTF8StringEncoding];
dataStr = [encodeData base64EncodedStringWithOptions:0];
I want to transform it to swift. Here is the swift code:
let dataEncodeTemp = dataTempStr.data(using: String.Encoding.utf8)
let dataStr = dataEncodeTemp?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
I think , the result should be the same. But it does not.
The Objective-C data:
(lldb) po str// initial
{"userType":2,"password":"qazwsx2","account":"15921810000"}
(lldb) po dataStr // encoded
eyJ1c2VyVHlwZSI6MiwicGFzc3dvcmQiOiJxYXp3c3gyIiwiYWNjb3VudCI6IjE1OTIxODE3MDUzIn0=
The swift data:
po dataTempStr // initial
"{\"userType\":2,\"account\":\"15921810000\",\"password\":\"qazwsx2\"}"
(lldb) po dataStr
▿ Optional<String> // encoded
- some : "eyJ1c2VyVHlwZSI6MiwiYWNjb3VudCI6IjE1OTIxODE3MDUzIiwicGFzc3dvcmQiOiJxYXp3c3gyIn0="
I want to know why , and solve it.
I shall try the bridge.
Any good solution?
Upvotes: 1
Views: 66
Reputation: 29009
Those aren't ever going to match, seeing as the two strings have JSON keys in differing orders; one is userType
, password
, account
; the other is userType
, account
, password
.
Upvotes: 2