简体   繁体   English

Alamofire:失败响应序列化失败

[英]Alamofire: FAILURE responseSerializationFailed

I'm trying to get the JSON from a URL to download using Alamofire . 我正在尝试从URL获取JSON ,以使用Alamofire下载。

Alamofire.request(requrl, method: .get, encoding: JSONEncoding.default)
        .responseJSON { response in
            print(response.result)
            print(response.value)
            debugPrint(response)


            }

However the value of response.value is nil, and the request result status is FAILURE. 但是response.value值为nil,请求结果状态为FAILURE。 The following is in the logs: 以下是日志中:

>[Data]: 919 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.}))
[Timeline]: Timeline: { "Request Start Time": 561988246.258, "Initial Response Time": 561988246.446, "Request Completed Time": 561988246.447, "Serialization Completed Time": 561988246.447, "Latency": 0.189 secs, "Request Duration": 0.189 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.190 secs

The JSON url in a browser returns: 浏览器中的JSON网址返回: 在此处输入图片说明

php script PHP脚本

<?php
header('Content-type: application/json');
//header('Content-Type: html; charset=utf-8');
$sqlstatement = $_GET["sqlstatement"];
// Create connection
$dbConnection=mysqli_connect("***.***.gear.host","****","*****!","****");

//$sqlstatement = "SELECT * FROM reeds.tbl_user";
// Check connection
if (mysqli_connect_errno())
{
  // Print error message 
  echo mysqli_connect_error();
}

// Stores SQL statement, selecting all objects from testcomputing.name


// Check to ensure results > = 1
if ($result = mysqli_query($dbConnection, $sqlstatement))
{
    // If so, then create a results array and a temporary one to hold the data
    $resultArray = array();
    $tempArray = array();

    // Loop through each row in the result set
    while($row = $result->fetch_object())
    {
        // Add each row into our results array
    $tempArray = $row;
     array_push($resultArray, $tempArray);
    }

    // Encode the array to JSON and output the results
    echo json_encode($resultArray);
}

// Close connections
mysqli_close($dbConnection);
?>

The issue was associated with the hosting provider. 该问题与托管服务提供商有关。 The provider I was originally using had strange security protocols installed, as such no JSON was being returned, after switching it work perfectly. 我最初使用的提供程序已安装了奇怪的安全协议,因此在切换完美后,没有返回JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Alamofire-responseSerializationFailed - Alamofire - responseSerializationFailed 失败:responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) - FAILURE: responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) Alamofire - Alamofire.AFError.responseSerializationFailed - Xcode 8 - Alamofire - Alamofire.AFError.responseSerializationFailed - Xcode 8 Alamofire:responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) - Alamofire: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) Alamofire:文件下载和验证失败 - Alamofire: file download and validation failure 邮递员响应正常,但在Swift 3上Alamofire返回失败 - Postman Response OK, but on Alamofire return failure on Swift 3 Swift-失败:Alamofire中的responseValidationFailed(状态代码401) - Swift - FAILURE: responseValidationFailed in Alamofire (StatusCode 401) Alamofire召回api失败的最佳方法 - Alamofire best way to recall api on failure 如果在Alamofire 4中发生任何故障,如何捕获 - How to catch if any failure happens in Alamofire 4 如何检查Alamofire连接不良的失败? - How to check Alamofire failure of bad internet connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM