$result = json_decode(file_get_contents('route.json'),true);
// the json file is here: http://myweb.polyu.edu.hk/~11010482d/FSP/route.json
print_r($result);
//it show '[{"X":"264","Y":"115"},{"X":"328","Y":"115"},{"X":"309","Y":"216"},{"X":"256","Y":"222"},{"X":"227","Y":"217"},{"X":"227","Y":"238"},{"X":"223","Y":"221"},{"X":"223","Y":"205"},{"X":"254","Y":"206"},{"X":"309","Y":"182"},{"X":"309","Y":"98"},{"X":"327","Y":"98"}]'
//i have tried the string not using $result as variable to decode and it works.
$abcdefg = json_decode('[{"X":"264","Y":"115"},{"X":"328","Y":"115"},{"X":"309","Y":"216"},{"X":"256","Y":"222"},{"X":"227","Y":"217"},{"X":"227","Y":"238"},{"X":"223","Y":"221"},{"X":"223","Y":"205"},{"X":"254","Y":"206"},{"X":"309","Y":"182"},{"X":"309","Y":"98"},{"X":"327","Y":"98"}]',true);
print_r($abcdefg);
//it show Array ( [0] => Array ( [X] => 264 [Y] => 115 ) [1] => Array ( [X] => 328 [Y] => 115 ) [2] => Array ( [X] => 309 [Y] => 216 ) [3] => Array ( [X] => 256 [Y] => 222 ) [4] => Array ( [X] => 227 [Y] => 217 ) [5] => Array ( [X] => 227 [Y] => 238 ) [6] => Array ( [X] => 223 [Y] => 221 ) [7] => Array ( [X] => 223 [Y] => 205 ) [8] => Array ( [X] => 254 [Y] => 206 ) [9] => Array ( [X] => 309 [Y] => 182 ) [10] => Array ( [X] => 309 [Y] => 98 ) [11] => Array ( [X] => 327 [Y] => 98 ) )
// and i want this result for the previous way.
无法通过变量解码json字符串
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- douyan1321 2013-05-08 04:14关注
Please try this:
<?php $json=file_get_contents('http://myweb.polyu.edu.hk/~11010482d/FSP/route.json'); $json=substr($json,1,-1); $result = json_decode($json,true); print_r($result); ?>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 有没有帮写代码做实验仿真的
- ¥15 報錯:Person is not mapped,如何解決?
- ¥30 vmware exsi重置后登不上
- ¥15 c++头文件不能识别CDialog
- ¥15 Excel发现不可读取的内容