求大神解答這個json如何轉為數組
{trend : 3,yearLowPrice : 99.9,points : [['2014-10-29',139.9],['2014-11-11',115.9],['2014-11-12',139.9],['2014-12-12',129],['2014-12-13',139.9],['2015-01-01',119],['2015-01-06',139.9],['2015-02-12',159.9],['2015-02-27',139.9],['2015-03-06',119],['2015-03-08',139.9],['2015-03-23',99.9],['2015-03-27',139.9],['2015-04-27',139.91]]}
找在線校驗工具老提示錯誤
$s =<<< TXT
{trend : 3,yearLowPrice : 99.9,points : [['2014-10-29',139.9],['2014-11-11',115.9],['2014-11-12',139.9],['2014-12-12',129],['2014-12-13',139.9],['2015-01-01',119],['2015-01-06',139.9],['2015-02-12',159.9],['2015-02-27',139.9],['2015-03-06',119],['2015-03-08',139.9],['2015-03-23',99.9],['2015-03-27',139.9],['2015-04-27',139.91]]}
TXT;
$s = preg_replace_callback('/[\w.-]+/', function($m) { return '"'.$m[0].'"'; }, str_replace("'", '', $s));
$a = json_decode($s, true);
print_r($a);
Array
(
[trend] => 3
[yearLowPrice] => 99.9
[points] => Array
(
[0] => Array
(
[0] => 2014-10-29
[1] => 139.9
)
[1] => Array
(
[0] => 2014-11-11
[1] => 115.9
)
[2] => Array
(
[0] => 2014-11-12
[1] => 139.9
)
[3] => Array
(
[0] => 2014-12-12
[1] => 129
)
[4] => Array
(
[0] => 2014-12-13
[1] => 139.9
)
[5] => Array
(
[0] => 2015-01-01
[1] => 119
)
[6] => Array
(
[0] => 2015-01-06
[1] => 139.9
)
[7] => Array
(
[0] => 2015-02-12
[1] => 159.9
)
[8] => Array
(
[0] => 2015-02-27
[1] => 139.9
)
[9] => Array
(
[0] => 2015-03-06
[1] => 119
)
[10] => Array
(
[0] => 2015-03-08
[1] => 139.9
)
[11] => Array
(
[0] => 2015-03-23
[1] => 99.9
)
[12] => Array
(
[0] => 2015-03-27
[1] => 139.9
)
[13] => Array
(
[0] => 2015-04-27
[1] => 139.91
)
)
)