Json response via PHP [已关闭]

0kjbasz6  于 2023-08-02  发布在  PHP
关注(0)|答案(1)|浏览(112)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
昨天关门了。
Improve this question
如何返回以下响应?
成功后应返回:

{ status : "ok", data : 
  [ { franchisor_no : <franchisor number>
    , franchisor_status : uncollected | active | delivered | returned | exception
  , events_list : 
    [ { date: <date>, status : uncollected | active | delivered | returned | exception
       , description: <optional description>
       , code: <optional code, may map to the defined franchisor codes>
       , location: <optional location, such as city or hub>.
       ... raw_event: <the original event as received from the franchisor API. mandatory 
... } ] } .... ] }

字符串
我正在使用这段代码,但没有向我的服务器发送任何响应。请让我知道,如果有任何错误,在这个代码?

<?php
$data = json_decode(file_get_contents("php://input"));

echo json_encode = [
    "status" => "ok",
    "data" => [
        [
            "franchisor_no" => "1210110080",
            "franchisor_status" => "exception",
            "events_list" => [
                [
                    "date" => "30-07-2023",
                    "status" => "exception",
                    "description" => "optional",
                    "code" => "optional",
                    "location" => "optional",
                    "raw_event" => "mandatory"
                ],
            ],
        ],
    ],
];

z4bn682m

z4bn682m1#

应该是的

echo json_encode([
"status" => "ok",
"data" => [
    [
        "franchisor_no" => "1210110080",
        "franchisor_status" => "exception",
        "events_list" => [
            [
                "date" => "30-07-2023",
                "status" => "exception",
                "description" => "optional",
                "code" => "optional",
                "location" => "optional",
                "raw_event" => "mandatory"
            ],
        ],
    ],
]]);

字符串
您没有调用json_encode()。你只是在它前面加上一个等号

相关问题