ios - Alamofire:失败响应序列化失败

标签 ios swift alamofire

我正在尝试使用 Alamofire 从 URL 获取 JSON 下载。

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


            }

但是response.value的值为nil,请求结果状态为FAILURE。日志中包含以下内容:

>[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

浏览器中的 JSON url 返回: enter image description here

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);
?>

最佳答案

该问题与托管提供商有关。我最初使用的提供程序安装了奇怪的安全协议(protocol),因此在切换后它工作完美,没有返回任何 JSON。

关于ios - Alamofire:失败响应序列化失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52948481/

相关文章:

ios - 如何在 Swift 中将旁边带有 ImageView 的 Label 居中?

ios - 此日期时间响应的正确格式是什么

ios - objective-c 以编程方式从钥匙串(keychain)中删除帐户

ios - 在 Swift 中点击并按住 UIButton?

swift - NSLock.lock() 在锁定已持有时执行?

ios - 如何创建与 Alamofire 一起使用的 NTLM 身份验证 header ?

ios - 没有可见的@interface 'PhotosTableViewController'声明选择器 'viewWithImageName'

json - 使用Swift从YouTube API解析JSON响应

swift - 从函数返回类类型?

ios - Alamofire 图像缓存?