简体   繁体   中英

json viewer library for php

I would like to show my json string like this :

在此输入图像描述

but if I echo my json output it shows like this:

{"Status":2,"TokenReg":"eeea7930efeb7715697a2035fcee3fdf","AllScores":"305","User_ID":"16433"}

is there any plugin/library to show json string as well as above image (formatted json) ?

When you use json_encode in PHP you can specify the JSON_PRETTY_PRINT option.

echo json_encode(["foo" => ["bar" => ["baz" => "quix"]]], JSON_PRETTY_PRINT);

This gives you output like this.

{
    "foo": {
        "bar": {
            "baz": "quix"
        }
    }
}

If what you already have is a string you can just decode first and the encode.

$str = '{"Status":2,"TokenReg":"eeea7930efeb7715697a2035fcee3fdf","AllScores":"305","User_ID":"16433"}';
echo json_encode(json_decode($str), JSON_PRETTY_PRINT);

This should give you the desired output.

{
    "Status": 2,
    "TokenReg": "eeea7930efeb7715697a2035fcee3fdf",
    "AllScores": "305",
    "User_ID": "16433"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM