将JSON解码为PHP数组时会丢失一些数据
我可以在PHP中将JSON解码为数组,但在解码为数组时,JSON中包含的一些数据会消失 这是我的JSON文件将JSON解码为PHP数组时会丢失一些数据,php,arrays,json,Php,Arrays,Json,我可以在PHP中将JSON解码为数组,但在解码为数组时,JSON中包含的一些数据会消失 这是我的JSON文件 [ { "name": "Games1", "price": "€ 25.53", "platform": "<span class=\"platform battle-net\"></span>", "region": "GLOBAL", "url": "localhost" }, { "name":
[
{
"name": "Games1",
"price": "€ 25.53",
"platform": "<span class=\"platform battle-net\"></span>",
"region": "GLOBAL",
"url": "localhost"
},
{
"name": "Games2",
"price": "€ 24.99",
"platform": "<span class=\"platform xbox-live\"></span>",
"region": "GLOBAL",
"url": "localhost"
}
]
我在平台上的价值消失了。有人知道问题出在哪里吗?为了将HTML保存在JSON中,您必须遵循多个规则:
&欧元代码>
标记,然后像这样存储它们的类名:“平台”:“战网”
或“平台”:“xbox live”
您的JSON包含HTML标记,当浏览器显示打印结果时,这些标记将被解释。
。使用浏览器的“查看源”命令查看原始输出,您应该可以看到跨距
您还可以使用htmlentities()
将它们转换为转义字符,浏览器将按原样显示转义字符
$output = print_r($data, true);
echo "<pre>" . htmlentities($output, ENT_COMPAT) . "</pre>";
$output=print\r($data,true);
“回声”。htmlentities($output,ENT\u COMPAT)。"";
使用
也会保持格式。你能给出var_dump($data)的输出吗?如果你使用浏览器查看输出,然后查看源代码,输出很可能在那里,但是你的浏览器正在解释HTML标记。为什么你需要所有str_replace()
的东西?为什么在game.json
中会有无关的字符?
Array ( [0] => Array ( [name] => Games1 [price] => € 25.53 [platform] => [region] => GLOBAL [url] => localhost )
[1] => Array ( [name] => Games2 [price] => € 24.99 [platform] => [region] => GLOBAL [url] => localhost ) )
$output = print_r($data, true);
echo "<pre>" . htmlentities($output, ENT_COMPAT) . "</pre>";