如何在php中回显json?服务器发给我json。
$i=$_POST["id"];
if($i==1){
// here i must echo this
{
"item":
{
"html":
[{
"description": "some text",
"n": "1"
}],
"table": {
"1": {
"line": [{
"number": "",
"value": ""
}
]
}
},
"videos": [],
"urlext": [],
"imgs": [ {
"size": {
"root": "xxx xxx"
}
}]
}
}
}
else {
// here i must echo another one
{
"item":
{
"html":
[{
"description": "some text",
"n": "1"
}],
"table": {
"1": {
"line": [{
"number": "",
"value": ""
}
]
}
},
"videos": [],
"urlext": [],
"imgs": [ {
"size": {
"root": "xxx xxx"
}
}]
}
}
}
}
答案 0 :(得分:1)
只需构建一个需要作为json发送的数据的关联数组,并使用json_encode()
来渲染json
$data = array( 'name' => 'foo',
'some' => 'thing'
);
echo json_encode($data);