json_encode() 向我的 REST API

问题描述

我正在尝试为我的应用程序 JSON 数据提供服务。在大多数情况下它有效。但带来了一些挑战。 所以我从我的数据库提取数据,它的内容没有斜线。

让我向您展示一些代码。 这是我的 SendResponse 函数()(缩短)

function send_response($res) {
        if($res) {
            $res['_total'] = count($res);
            if('success' === $res['status']) {
                $res['code'] = 200;
            }
            
            header_remove();
            header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
            header('Content-Type: application/json');
            header('Status: '.$res['code']);

            echo json_encode($res,JSON_FORCE_OBJECT | JSON_PRETTY_PRINT | JSON_UnesCAPED_SLASHES );
        } 
    }

当我从我的 API 请求数据时,我得到如下所示的响应。 这样做的问题是,它在 Javascript 端访问数据具有挑战性,因为其中一半显示为实际的 JSON,但部分不是(即:items 数组元素)。

enter image description here

在这里做错了什么?

enter image description here

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)