How to output JSON data correctly using PHP

前端 未结 7 1522
时光说笑
时光说笑 2021-01-04 04:03

I\'m developing an Android app, and for the API I\'m sending my requests to a URL that should return JSON data.

This is what I\'m getting in my output:

7条回答
  •  Happy的楠姐
    2021-01-04 04:12

    Your problem is actually very easy to solve. The Chrome JSON Formatter plugin only formats your output if the Content-Type header is set to application/json.

    The only thing you need to change in your code is to use header('Content-Type: application/json'); in your PHP code, before returning the json-encoded data.

提交回复
热议问题