【问题标题】:Swift Json error garbageSwift Json 错误垃圾
【发布时间】:2015-10-22 20:44:31
【问题描述】:

当我向我的 php api 发出 post 请求时,我的 swift 应用程序给出了错误:

最后的垃圾

这是我的 json 代码(仅供试用):

    function getTips($params)
{
    $blessure = $params[0];
    switch($blessure)
    {
    case "hoofd":
        echo '
        "hoofd": [
                {
                    "naam": "neus in de kom",
                    "beschrijving": "neus zit in de kom",
                    "categorie": "hoofd"
                },
                {
                    "naam": "oor in de kom",
                    "beschrijving": "oor zit in de kom",
                    "categorie": "hoofd"
                }
            ]
        ';
     break;

     default:
     header("HTTP/1.0 404 Not Found");
     break;   
    }
}

我在这里做错了什么?

【问题讨论】:

    标签: php json swift


    【解决方案1】:

    您可以尝试发送标头

    header('Content-type: application/json');
    

    或者把你的数据放在 assoc 数组中,然后用 json_encode 包装,像这样

    echo json_encode( array(
       array( 'naam' => 'neus in de kom',
              'beschrijving'=> 'neus zit in de kom',
       ),
       array()
    ));
    die();
    

    试试看)

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2019-11-29
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2015-06-27
      • 2020-07-21
      • 2016-03-25
      • 1970-01-01
      相关资源
      最近更新 更多