Json response via PHP [已关闭]

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

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

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

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

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

  1. <?php
  2. $data = json_decode(file_get_contents("php://input"));
  3. echo json_encode = [
  4. "status" => "ok",
  5. "data" => [
  6. [
  7. "franchisor_no" => "1210110080",
  8. "franchisor_status" => "exception",
  9. "events_list" => [
  10. [
  11. "date" => "30-07-2023",
  12. "status" => "exception",
  13. "description" => "optional",
  14. "code" => "optional",
  15. "location" => "optional",
  16. "raw_event" => "mandatory"
  17. ],
  18. ],
  19. ],
  20. ],
  21. ];

z4bn682m

z4bn682m1#

应该是的

  1. echo json_encode([
  2. "status" => "ok",
  3. "data" => [
  4. [
  5. "franchisor_no" => "1210110080",
  6. "franchisor_status" => "exception",
  7. "events_list" => [
  8. [
  9. "date" => "30-07-2023",
  10. "status" => "exception",
  11. "description" => "optional",
  12. "code" => "optional",
  13. "location" => "optional",
  14. "raw_event" => "mandatory"
  15. ],
  16. ],
  17. ],
  18. ]]);

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

展开查看全部

相关问题