解密我的json字符串失败:(

时间:2017-04-06 10:08:04

标签: php json

如何使用php解码它

$myjson = [{"type":"laser","material":"1","quantity":1000},
{"type":"motors","material":"1","quantity":1491477212},
{"type":"shield","material":"1","quantity":1491531189},
{"type":"hp","material":"1","quantity":1491531201}] ;

1 个答案:

答案 0 :(得分:0)

检查此代码,您错过了"'"在开始和结束"'"。我现在格式化你可以使用这个代码

<?php
$myjson = '[{"type":"laser","material":"1","quantity":1000},{"type":"motors","material":"1","quantity":1491477212},{"type":"shield","material":"1","quantity":1491531189},{"type":"hp","material":"1","quantity":1491531201}]' ;
$array = json_decode($myjson);

echo "<pre>";
print_r($array);