此问题在此处已有答案:
Pretty-Printing JSON with PHP(27个答案)
关闭5个月前.
$arr = array(
'toemail'=>$v->agent_primary_email,
'agentname'=>$v->agent_firstname,
'agentid'=>$v->agent_id,
'subject'=>'The details of total number of properties saved by your clients',
'totalprop'=>$v->prop_count
);
echo json_encode($arr);exit;
输出如下
{"toemail":"abc@gmail.com","agentname":"john","agentid":"110012","subject":"The details of total number of properties saved by your clients","totalprop":"131"}
但是,我应该做些什么更改才能使输出看起来像这样呢?
{"toemail":"abc@gmail.com",
"agentname":"john",
"agentid":"110012",
"subject":"The details of total number of properties saved by your clients",
"totalprop":"131"}
1条答案
按热度按时间kfgdxczn1#
使用
JSON_PRETTY_PRINT
并且还需要使用echo "<pre>"
;From PHP Manual:在返回的数据中使用空格来设置其格式。自PHP 5.4.0起可用
结果: