我正在使用Authorize.net支付api,同时使交易请求收到错误 code = E00001 text ="解析值时遇到意外的字符:c。路径'',第0行,第0位
如果有人知道要进行交易请求,请帮助: 我使用以下代码:
let json = """
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": "2",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "\(totalAmount)",
"payment": {
"opaqueData": {
"dataDescriptor": "\(inResponse.getOpaqueData().getDataDescriptor())",
"dataValue": "\(inResponse.getOpaqueData().getDataValue())"
}
}
}
}
}
"""
let jsonData = Data(json.utf8)
do {
let transaction = try JSONDecoder().decode(Transaction.self, from: jsonData)
print(transaction)
// encoding
let encodedData = try JSONEncoder().encode(transaction)
print(String(data: encodedData, encoding: .utf8)!)
//Data to [String : Any]
do {
let params = try JSONSerialization.jsonObject(with: encodedData, options: []) as! [String: Any]
print(params)
Alamofire.request(“https://apitest.authorize.net/xml/v1/request.api”, method: .post, parameters: params).responseJSON {response in
print(response)
}
} catch {
print(error)
}