How to output JSON data correctly using PHP

前端 未结 7 1513
时光说笑
时光说笑 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条回答
  •  没有蜡笔的小新
    2021-01-04 04:20

    PHP's json_encode function takes a second argument, for $options. Here you can use JSON_PRETTY_PRINT to print it like you see in the Twitter API

    E.g.

    echo json_encode($my_array, JSON_PRETTY_PRINT);
    

提交回复
热议问题