我正在使用文件获取内容方法来获取统计数据,如下所示
$val = file_get_contents('https://example.com/getStatsData');
我得到的输出值如下
{"msg":"success","data":[[{"stats_abc":"1223","stats_bcd":"55684","stats_cda":"14999","stats_def":232456,"stats_efg":"432868","stats_fgh":"7558","stats_ghi":"3,778.72","stats_date":"20-01-2018 17:00 PM"}],null]}
但是当我将其解码为 json_decode($val) 时。它没有显示任何内容。 谁能帮助我将上述数据作为数组/对象获取?
提前致谢
最佳答案
这确实有效:
<?php
$json = '{
"msg": "success",
"data": [
[{
"stats_abc": "1223",
"stats_bcd": "55684",
"stats_cda": "14999",
"stats_def": 232456,
"stats_efg": "432868",
"stats_fgh": "7558",
"stats_ghi": "3,778.72",
"stats_date": "20-01-2018 17:00 PM"
}], null
]
}';
echo '<pre>';
print_r(json_decode($json));
echo '</pre>';
结果:
stdClass Object
(
[msg] => success
[data] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[stats_abc] => 1223
[stats_bcd] => 55684
[stats_cda] => 14999
[stats_def] => 232456
[stats_efg] => 432868
[stats_fgh] => 7558
[stats_ghi] => 3,778.72
[stats_date] => 20-01-2018 17:00 PM
)
)
[1] =>
)
)
只是为了表明 json 本身没问题。
关于javascript - 返回值显示为字符串而不是 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48355886/