如何在php中正确写入? json
问题描述:
如何在php中回显json?服务器向我发送json。如何在php中正确写入? 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"
}
}]
}
}
}
}
答
只是生成数据的关联数组,你需要发送的JSON和使用json_encode()
渲染JSON
$data = array('name' => 'foo',
'some' => 'thing'
);
echo json_encode($data);
回声json_encode($ yourContent); – sanj 2013-02-25 14:21:53
[json_encode()](http://php.net/manual/en/function.json-encode.php)。你是怎么找不到Google的,甚至是搜索这个网站的? – SDC 2013-02-25 14:21:56
SO正在被轰炸,显示没有研究的努力的问题,这些天..至少PHP的问题 – Broncha 2013-02-25 14:25:19