且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 PHP 中回显 JSON

更新时间:2023-11-14 16:07:28

如果你想从 JSON 编码或解码数组,你可以使用这些函数

if you want to encode or decode an array from or to JSON you can use these functions

$myJSONString = json_encode($myArray);
$myArray = json_decode($myString);

json_encode 将产生一个由(多维)数组构建的 JSON 字符串.json_decode 将产生一个由格式良好的 JSON 字符串构建的数组

json_encode will result in a JSON string, built from an (multi-dimensional) array. json_decode will result in an Array, built from a well formed JSON string

使用 json_decode 您可以从 API 中获取结果并只输出您想要的内容,例如:

with json_decode you can take the results from the API and only output what you want, for example:

echo $myArray['payload']['ign'];