你好我在SWIFT新的和我的問題,我做了一個請求,服務器用post方法,我也得到響應與良好的JSON,之後,我makeing另一用GET方法請求,但我得到這個錯誤錯誤域= NSCocoaErrorDomain代碼= 3840「無效的周圍字符值0
錯誤: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(錯誤域= NSCocoaErrorDomain代碼= 3840 「無效圍繞字符值0」 的UserInfo = {NSDebugDescription =無效圍繞字符0})
爲請求中的參數值:
static func getInformationFromConfig(token: String, config: String, section : String, option: String) -> [String:Any] {
let getInformationFromConfigparam: [String : Any] = ["jsonrpc": "2.0",
"id": 1,
"method": "call",
"params": [ token, "uci", "get", [ "config": config, "section": section, "option": option]]
]
return getInformationFromConfigparam
}
public func device(token: String, loginCompletion: @escaping (Any) ->()) {
let deviceinfo = JsonRequests.getInformationFromConfig(token: token, config: "wireless", section: "@wifi-iface[0]", option: "mode")
makeWebServiceCall(urlAddress: URL, requestMethod: .get, params: deviceinfo, completion: { (JSON : Any) in
loginCompletion(JSON)
})
}
請求:
private func makeWebServiceCall (urlAddress: String, requestMethod: HTTPMethod, params:[String:Any], completion: @escaping (_ JSON : Any) ->()) {
Alamofire.request(urlAddress, method: requestMethod, parameters: params, encoding: JSONEncoding.default).responseJSON{ response in
switch response.result {
case .success(let value):
let json = JSON(value)
if let jsonData = response.result.value {
completion(jsonData)
}
case .failure(let error):
completion("Failure Response: \(error)")
ResponseString響應:
[Request]: GET http://192.168.1.1/ubus
[Response]: <NSHTTPURLResponse: 0x60000003c4a0> { URL: http://192.168.1.1/ubus } { status code: 400, headers {
Connection = "Keep-Alive";
"Content-Type" = "text/html";
"Keep-Alive" = "timeout=20";
"Transfer-Encoding" = Identity;
} }
[Data]: 35 bytes
[Result]: FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
(HTTP [周圍字符0 Alamofire無效值]的可能重複:// stackoverflow.com/questions/32355850/alamofire-invalid-value-around-character-0) –