gpt4 book ai didi

php - Swift Json 错误垃圾

转载 作者:行者123 更新时间:2023-11-30 13:58:30 25 4
gpt4 key购买 nike

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

Garbage at end

这是我的 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;
}
}

我在这里做错了什么?

最佳答案

您可以尝试发送 header

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

尝试一下)

关于php - Swift Json 错误垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33290426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com