我正在使用Jnd的Zend Framework帮助器。 我使用创建的方法toArray()从域实体返回一个数据数组。
有没有办法将格式从整洁改为漂亮?
PHP
$data = array(
"success"=>true,
"user"=>array($user->toArray())
);
$this->_helper->json($data);
身体反应:
{"success":true,"user":[{"id":9,"displayName":"joey","firstName":"joe","lastName":"blow","email":"joeblow@yahoo.com","role":"user"}]}
要:
{
"success":true,
"user": [{
"id":9,
"displayName":"joey",
"firstName":"joe",
"lastName":"blow",
"email":"joeblow@yahoo.com",
"role":"user"
}]
}
答案 0 :(得分:1)
它没有经过测试,并且取决于你的一些json实现,但你可以尝试:
$json = Zend_Json::encode($data);
$json = Zend_Json::prettyPrint($json);
$this->_helper->json($json, true, array('encodeData' => false));
答案 1 :(得分:1)
试试这个:
$json = Zend_Json::encode($phpNative);
echo Zend_Json::prettyPrint($json, array("indent" => " "));
LINK:http://framework.zend.com/manual/en/zend.json.basics.html