qq_22916833 2015-04-27 09:41 采纳率: 100%
浏览 1665
已采纳

求大神解答这个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]]}

找在线校验工具老提示错误

  • 写回答

5条回答 默认 最新

  • xuzuning 2015-04-27 09:47
    关注
     $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
                    )
    
            )
    
    )
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。