我目前正在尝试从JSON文件中读取坐标,并将其保存到数组中以备将来使用。但是,我无法成功读取文件。我的JSON文件具有以下格式(我只关心cX和cY):
{
"cX": [
246,
1253,
1464,
1183
],
"cY": [
223,
138,
383,
114
],
"scroll": [
0,
90,
0,
0
],
"sessionID": [
"f06807c10fb31d5530ad8c4236b94ee2",
"f06807c10fb31d5530ad8c4236b94ee2",
"f06807c10fb31d5530ad8c4236b94ee2",
"f06807c10fb31d5530ad8c4236b94ee2"
],
"Time": [
"11:30:01",
"11:30:02",
"11:30:03",
"11:30:03"
],
"elem": [
"H1",
"H1",
"H1",
"BODY"
]
}
我正在尝试使用以下php代码:
<?php
$string = file_get_contents("./PHP/JSON/clicks.json");
$json_a = json_decode($string, true);
for($idx = 0; $idx < count($json_a); $idx++){
$obj = (Array)$json_a[$idx];
echo $obj["cX"];
?>
<?php
$string = file_get_contents("./PHP/JSON/clicks.json");
$json_a = json_decode($string);
$cx= $json_a->cX;
$cy=$json_a->cY;
?>
希望对您有帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句