程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> php-求大神解答這個json如何轉為數組

php-求大神解答這個json如何轉為數組

編輯:編程綜合問答
求大神解答這個json如何轉為數組

求大神解答這個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
                )

        )

)


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved