如何转换此字符串json PHP

时间:2013-05-19 16:31:21

标签: php json

我有以下字符串

[[[2401263,"Chelsea","Everton",1,"2013-05-19T15:00:00.0000000",[[4977131,39]],1,1,1,[1,30,"2013-05-19T15:00:48.4400000",0],17,"/sports/soccer/england_premier_league",,],[2401266,"Newcastle","Arsenal",1,"2013-05-19T15:00:00.0000000",[[4977137,39]],0,0,1,[1,90,"2013-05-19T15:01:10.8430000",0,0,0],18,"/sports/soccer/england_premier_league",0,0],[2401267,"Southampton","Stoke City",1,"2013-05-19T15:00:00.0000000",[[4977139,39]],0,0,1,[1,180,"2013-05-19T15:02:56.8230000",0,0,0],18,"/sports/soccer/england_premier_league",0,0],[2401269,"Tottenham","Sunderland",1,"2013-05-19T15:00:00.0000000",[[4977143,39]],0,0,1,[1,30,"2013-05-19T15:00:48.7070000",0,0,0],18,"/sports/soccer/england_premier_league",0,0],[2401270,"West Brom","Man Utd",1,"2013-05-19T15:00:00.0000000",[[4977145,39]],0,2,1,[1,90,"2013-05-19T15:03:06.0200000",0],17,"/sports/soccer/england_premier_league",,],[2401271,"Wigan","Aston Villa",1,"2013-05-19T15:00:00.0000000",[[4977147,39]],1,1,1,[1,30,"2013-05-19T15:00:48.7530000",0],17,"/sports/soccer/england_premier_league",,],[2408847,"Dep La Coruna","Espanyol",1,"2013-05-19T15:00:00.0000000",[[4979597,39]],0,0,1,[1,90,"2013-05-19T15:01:11.2030000",0,0,0],27,"/sports/soccer/spain_la_liga",0,0],[2408897,"Hercules","Mirandes",1,"2013-05-19T15:00:00.0000000",[[4987070,39]],0,0,1,[1,30,"2013-05-19T15:00:48.4570000",0],18,"/sports/soccer/spain_segunda",,],[2408960,"Korona Kielce","Jagiellonia Bialystok",1,"2013-05-19T15:00:00.0000000",[[4999194,39]],1,0,1,[1,30,"2013-05-19T15:00:54.3700000",0],17,"/sports/soccer/poland_ekstraklasa",,],[2412214,"Varnamo IFK","GAIS Goteborg",1,"2013-05-19T15:00:00.0000000",[[4988445,39]],0,0,1,[1,30,"2013-05-19T15:00:48.3800000",0],27,"/sports/soccer/sweden_superettan",,],[2412215,"Panos Ljungskile","Jonkopings Sodra",1,"2013-05-19T15:00:00.0000000",[[4988447,39]],0,0,1,[1,30,"2013-05-19T15:00:54.4000000",0],27,"/sports/soccer/sweden_superettan",,],[2413870,"PAOK Saloniki","Pas Giannina",1,"2013-05-19T15:15:00.0000000",[[4999196,39]],0,0,1,[1,570,"2013-05-19T15:15:36.1670000",0],18,"/sports/soccer/greece_super_league",,],[2417005,"Turkey U16","Russia U16",1,"2013-05-19T14:00:00.0000000",[[5001521,39]],1,0,1,[2,2790,"2013-05-19T15:02:31.6370000",0],0,"/sports/soccer/friendly_intl_u16",,],[2401264,"Liverpool","Queens P Rangers",1,"2013-05-19T15:00:00.0000000",[[4977133,39]],1,0,1,[1,30,"2013-05-19T15:00:48.3470000",0],17,"/sports/soccer/england_premier_league",,],[2401268,"Swansea","Fulham",1,"2013-05-19T15:00:00.0000000",[[4977141,39]],0,1,1,[1,30,"2013-05-19T15:00:48.8630000",0],17,"/sports/soccer/england_premier_league",,],[2408652,"Zenit St. Petersburg","Volga Nizhniy Novgorod",1,"2013-05-19T14:30:00.0000000",[[4987679,39]],1,1,1,[3,2790,"2013-05-19T15:18:21.6570000",0,0,0],24,"/sports/soccer/russia_premier_liga",0,0],[2411551,"Diosgyor Balaton","Kecskemet",1,"2013-05-19T14:30:00.0000000",[[4999186,39]],0,1,1,[3,2730,"2013-05-19T15:18:21.6230000",0,0,0],16,"/sports/soccer/hungary_nb_i",0,0],[2414581,"Utrecht","Heerenveen",1,"2013-05-19T14:30:00.0000000",[[4999188,39]],1,0,1,[3,2730,"2013-05-19T15:16:28.2570000",0],16,"/sports/soccer/netherlands_eredivisie",,],[2414656,"Roda","De Graafschap",1,"2013-05-19T14:30:00.0000000",[[4999190,39]],3,1,1,[3,2790,"2013-05-19T15:19:08.9100000",0],16,"/sports/soccer/netherlands_eerste_div",,],[2401265,"Man City","Norwich",1,"2013-05-19T15:00:00.0000000",[[4977135,39]],0,1,1,[1,30,"2013-05-19T15:00:48.3170000",0],18,"/sports/soccer/england_premier_league",,],[2408690,"Sturm Graz","Ried",1,"2013-05-19T14:00:00.0000000",[[4986537,39]],1,1,1,[2,2790,"2013-05-19T15:04:14.3830000",0],16,"/sports/soccer/austria_bundesliga",,],[2401272,"West Ham","Reading",1,"2013-05-19T15:00:00.0000000",[[4977149,39]],1,0,1,[1,30,"2013-05-19T15:02:29.9830000",0],18,"/sports/soccer/england_premier_league",,],[2414909,"Peristeri","Ilisiakos BC",2,"2013-05-19T14:00:00.0000000",[[5001488,39]],48,49,1,[0,0,"2013-05-19T13:58:54.3470000",0],5,"/sports/basketball/greece_a1",,],[2417273,"Istanbul Teknik Uni","Duzce Belediye",2,"2013-05-19T15:00:00.0000000",[[5001550,39]],16,26,1,[0,0,"2013-05-19T15:09:41.7100000",0],6,"/sports/basketball/friendly",,],[2417087,"Benfica","Academica",2,"2013-05-19T15:00:00.0000000",[[5001548,39]],23,11,1,[0,0,"2013-05-19T15:09:32.3000000",0],6,"/sports/basketball/portugal_liga_tmn",,],[2416259,"Edouard Roger-Vasselin [FRA]","Alejandro Falla [COL]",6,"2013-05-19T14:55:00.0000000",[[5000358,39]],3001,4000,1,[0,0,"2013-05-19T04:13:48.0670000",0,3,0],2,"/sports/tennis/atp_nice",3,0],[2416856,"Flavia Pennetta [ITA]","Katarzyna Piter [POL]",6,"2013-05-19T10:00:00.0000000",[[5000441,39]],6000,5001,1,[0,0,"2013-05-19T05:28:36.6800000",0,3,0],2,"/sports/tennis/wta_strasbourg_qualifiers",3,0],[2416854,"Marta Domachowska [POL]","Arantxa Parra Santonja [ESP]",6,"2013-05-19T09:30:00.0000000",[[5000437,39]],46001,33000,1,[0,0,"2013-05-19T05:28:36.4700000",0,3,0],2,"/sports/tennis/wta_strasbourg_qualifiers",3,0],[2416265,"Finland ","USA ",8,"2013-05-19T14:00:00.0000000",[[5000330,39]],0,2,1,[0,0,"2013-05-19T03:57:47.0200000",0],0,"/sports/ice_hockey/world_championship_2013",,],[2416824,"Sunrisers Hyderabad","Kolkata Knight Riders",22,"2013-05-19T14:30:00.0000000",[[5001544,39]],0,0,1,[0,0,"2013-05-19T15:03:26.2830000",0],0,"/sports/cricket/indian_premier_league",,],[2417259,"El Jaish","Al Rayyan ",19,"2013-05-19T14:00:00.0000000",[[5001502,39]],1,2,1,[0,0,"2013-05-19T14:06:27.8300000",0],0,"/sports/volleyball/friendlies_international",,]],[[1,"Soccer",1,1,["1x2","Asians","O/U"]],[2,"Basketball",2,2,["ML","Spread","O/U"]],[6,"Tennis",6,6,["Winner","Handicap","O/U"]],[8,"Ice Hockey",8,8,["Match Winner","Spread","O/U"]],[22,"Cricket",22,22,["MoneyLine","Spread","O/U"]],[19,"Volleyball",19,19,["ML","Sets Handicap","O/U"]]]]

如何使用php将其转换为JSON数据,以便在json_decode()

中使用

3 个答案:

答案 0 :(得分:1)

你的字符串看起来就像JS所期待的那样。

如果您有疑问,那么:

echo json_encode($String); 

答案 1 :(得分:1)

很简单:这看起来像JSON,但事实并非如此。使用以下代码将其转换为json_decode()将接受的内容:

$input = <<<EOL
[[[2401263,"Chelsea","Everton",1,"2013-05-19T15:00:00.0000000",[[4977131,39]],1$
EOL;

$input2 = str_replace(",,", ",null,", $input);
$json = str_replace(",]", "]", $input2);

var_dump(json_decode($json));

答案 2 :(得分:0)

似乎json确实无效......

 "/sports/soccer/england_premier_league", <---- remove this one too.
            , <------------ another comma

太多逗号,请删除

[
[
    [
        2401263,
        "Chelsea",
        "Everton",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977131,
                39
            ]
        ],
        1,
        1,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.4400000",
            0
        ],
        17,
        "/sports/soccer/england_premier_league"
    ],
    [
        2401266,
        "Newcastle",
        "Arsenal",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977137,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            90,
            "2013-05-19T15:01:10.8430000",
            0,
            0,
            0
        ],
        18,
        "/sports/soccer/england_premier_league",
        0,
        0
    ],
    [
        2401267,
        "Southampton",
        "Stoke City",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977139,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            180,
            "2013-05-19T15:02:56.8230000",
            0,
            0,
            0
        ],
        18,
        "/sports/soccer/england_premier_league",
        0,
        0
    ],
    [
        2401269,
        "Tottenham",
        "Sunderland",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977143,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.7070000",
            0,
            0,
            0
        ],
        18,
        "/sports/soccer/england_premier_league",
        0,
        0
    ],
    [
        2401270,
        "West Brom",
        "Man Utd",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977145,
                39
            ]
        ],
        0,
        2,
        1,
        [
            1,
            90,
            "2013-05-19T15:03:06.0200000",
            0
        ],
        17,
        "/sports/soccer/england_premier_league"
    ],
    [
        2401271,
        "Wigan",
        "Aston Villa",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977147,
                39
            ]
        ],
        1,
        1,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.7530000",
            0
        ],
        17,
        "/sports/soccer/england_premier_league"
    ],
    [
        2408847,
        "Dep La Coruna",
        "Espanyol",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4979597,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            90,
            "2013-05-19T15:01:11.2030000",
            0,
            0,
            0
        ],
        27,
        "/sports/soccer/spain_la_liga",
        0,
        0
    ],
    [
        2408897,
        "Hercules",
        "Mirandes",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4987070,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.4570000",
            0
        ],
        18,
        "/sports/soccer/spain_segunda"
    ],
    [
        2408960,
        "Korona Kielce",
        "Jagiellonia Bialystok",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4999194,
                39
            ]
        ],
        1,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:54.3700000",
            0
        ],
        17,
        "/sports/soccer/poland_ekstraklasa"
    ],
    [
        2412214,
        "Varnamo IFK",
        "GAIS Goteborg",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4988445,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.3800000",
            0
        ],
        27,
        "/sports/soccer/sweden_superettan"
    ],
    [
        2412215,
        "Panos Ljungskile",
        "Jonkopings Sodra",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4988447,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:54.4000000",
            0
        ],
        27,
        "/sports/soccer/sweden_superettan"
    ],
    [
        2413870,
        "PAOK Saloniki",
        "Pas Giannina",
        1,
        "2013-05-19T15:15:00.0000000",
        [
            [
                4999196,
                39
            ]
        ],
        0,
        0,
        1,
        [
            1,
            570,
            "2013-05-19T15:15:36.1670000",
            0
        ],
        18,
        "/sports/soccer/greece_super_league"
    ],
    [
        2417005,
        "Turkey U16",
        "Russia U16",
        1,
        "2013-05-19T14:00:00.0000000",
        [
            [
                5001521,
                39
            ]
        ],
        1,
        0,
        1,
        [
            2,
            2790,
            "2013-05-19T15:02:31.6370000",
            0
        ],
        0,
        "/sports/soccer/friendly_intl_u16"
    ],
    [
        2401264,
        "Liverpool",
        "Queens P Rangers",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977133,
                39
            ]
        ],
        1,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.3470000",
            0
        ],
        17,
        "/sports/soccer/england_premier_league"
    ],
    [
        2401268,
        "Swansea",
        "Fulham",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977141,
                39
            ]
        ],
        0,
        1,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.8630000",
            0
        ],
        17,
        "/sports/soccer/england_premier_league"
    ],
    [
        2408652,
        "Zenit St. Petersburg",
        "Volga Nizhniy Novgorod",
        1,
        "2013-05-19T14:30:00.0000000",
        [
            [
                4987679,
                39
            ]
        ],
        1,
        1,
        1,
        [
            3,
            2790,
            "2013-05-19T15:18:21.6570000",
            0,
            0,
            0
        ],
        24,
        "/sports/soccer/russia_premier_liga",
        0,
        0
    ],
    [
        2411551,
        "Diosgyor Balaton",
        "Kecskemet",
        1,
        "2013-05-19T14:30:00.0000000",
        [
            [
                4999186,
                39
            ]
        ],
        0,
        1,
        1,
        [
            3,
            2730,
            "2013-05-19T15:18:21.6230000",
            0,
            0,
            0
        ],
        16,
        "/sports/soccer/hungary_nb_i",
        0,
        0
    ],
    [
        2414581,
        "Utrecht",
        "Heerenveen",
        1,
        "2013-05-19T14:30:00.0000000",
        [
            [
                4999188,
                39
            ]
        ],
        1,
        0,
        1,
        [
            3,
            2730,
            "2013-05-19T15:16:28.2570000",
            0
        ],
        16,
        "/sports/soccer/netherlands_eredivisie"
    ],
    [
        2414656,
        "Roda",
        "De Graafschap",
        1,
        "2013-05-19T14:30:00.0000000",
        [
            [
                4999190,
                39
            ]
        ],
        3,
        1,
        1,
        [
            3,
            2790,
            "2013-05-19T15:19:08.9100000",
            0
        ],
        16,
        "/sports/soccer/netherlands_eerste_div"
    ],
    [
        2401265,
        "Man City",
        "Norwich",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977135,
                39
            ]
        ],
        0,
        1,
        1,
        [
            1,
            30,
            "2013-05-19T15:00:48.3170000",
            0
        ],
        18,
        "/sports/soccer/england_premier_league"
    ],
    [
        2408690,
        "Sturm Graz",
        "Ried",
        1,
        "2013-05-19T14:00:00.0000000",
        [
            [
                4986537,
                39
            ]
        ],
        1,
        1,
        1,
        [
            2,
            2790,
            "2013-05-19T15:04:14.3830000",
            0
        ],
        16,
        "/sports/soccer/austria_bundesliga"
    ],
    [
        2401272,
        "West Ham",
        "Reading",
        1,
        "2013-05-19T15:00:00.0000000",
        [
            [
                4977149,
                39
            ]
        ],
        1,
        0,
        1,
        [
            1,
            30,
            "2013-05-19T15:02:29.9830000",
            0
        ],
        18,
        "/sports/soccer/england_premier_league"
    ],
    [
        2414909,
        "Peristeri",
        "Ilisiakos BC",
        2,
        "2013-05-19T14:00:00.0000000",
        [
            [
                5001488,
                39
            ]
        ],
        48,
        49,
        1,
        [
            0,
            0,
            "2013-05-19T13:58:54.3470000",
            0
        ],
        5,
        "/sports/basketball/greece_a1"
    ],
    [
        2417273,
        "Istanbul Teknik Uni",
        "Duzce Belediye",
        2,
        "2013-05-19T15:00:00.0000000",
        [
            [
                5001550,
                39
            ]
        ],
        16,
        26,
        1,
        [
            0,
            0,
            "2013-05-19T15:09:41.7100000",
            0
        ],
        6,
        "/sports/basketball/friendly"
    ],
    [
        2417087,
        "Benfica",
        "Academica",
        2,
        "2013-05-19T15:00:00.0000000",
        [
            [
                5001548,
                39
            ]
        ],
        23,
        11,
        1,
        [
            0,
            0,
            "2013-05-19T15:09:32.3000000",
            0
        ],
        6,
        "/sports/basketball/portugal_liga_tmn"
    ],
    [
        2416259,
        "Edouard Roger-Vasselin [FRA]",
        "Alejandro Falla [COL]",
        6,
        "2013-05-19T14:55:00.0000000",
        [
            [
                5000358,
                39
            ]
        ],
        3001,
        4000,
        1,
        [
            0,
            0,
            "2013-05-19T04:13:48.0670000",
            0,
            3,
            0
        ],
        2,
        "/sports/tennis/atp_nice",
        3,
        0
    ],
    [
        2416856,
        "Flavia Pennetta [ITA]",
        "Katarzyna Piter [POL]",
        6,
        "2013-05-19T10:00:00.0000000",
        [
            [
                5000441,
                39
            ]
        ],
        6000,
        5001,
        1,
        [
            0,
            0,
            "2013-05-19T05:28:36.6800000",
            0,
            3,
            0
        ],
        2,
        "/sports/tennis/wta_strasbourg_qualifiers",
        3,
        0
    ],
    [
        2416854,
        "Marta Domachowska [POL]",
        "Arantxa Parra Santonja [ESP]",
        6,
        "2013-05-19T09:30:00.0000000",
        [
            [
                5000437,
                39
            ]
        ],
        46001,
        33000,
        1,
        [
            0,
            0,
            "2013-05-19T05:28:36.4700000",
            0,
            3,
            0
        ],
        2,
        "/sports/tennis/wta_strasbourg_qualifiers",
        3,
        0
    ],
    [
        2416265,
        "Finland ",
        "USA ",
        8,
        "2013-05-19T14:00:00.0000000",
        [
            [
                5000330,
                39
            ]
        ],
        0,
        2,
        1,
        [
            0,
            0,
            "2013-05-19T03:57:47.0200000",
            0
        ],
        0,
        "/sports/ice_hockey/world_championship_2013"
    ],
    [
        2416824,
        "Sunrisers Hyderabad",
        "Kolkata Knight Riders",
        22,
        "2013-05-19T14:30:00.0000000",
        [
            [
                5001544,
                39
            ]
        ],
        0,
        0,
        1,
        [
            0,
            0,
            "2013-05-19T15:03:26.2830000",
            0
        ],
        0,
        "/sports/cricket/indian_premier_league"
    ],
    [
        2417259,
        "El Jaish",
        "Al Rayyan ",
        19,
        "2013-05-19T14:00:00.0000000",
        [
            [
                5001502,
                39
            ]
        ],
        1,
        2,
        1,
        [
            0,
            0,
            "2013-05-19T14:06:27.8300000",
            0
        ],
        0,
        "/sports/volleyball/friendlies_international"
    ]
],
[
    [
        1,
        "Soccer",
        1,
        1,
        [
            "1x2",
            "Asians",
            "O/U"
        ]
    ],
    [
        2,
        "Basketball",
        2,
        2,
        [
            "ML",
            "Spread",
            "O/U"
        ]
    ],
    [
        6,
        "Tennis",
        6,
        6,
        [
            "Winner",
            "Handicap",
            "O/U"
        ]
    ],
    [
        8,
        "Ice Hockey",
        8,
        8,
        [
            "Match Winner",
            "Spread",
            "O/U"
        ]
    ],
    [
        22,
        "Cricket",
        22,
        22,
        [
            "MoneyLine",
            "Spread",
            "O/U"
        ]
    ],
    [
        19,
        "Volleyball",
        19,
        19,
        [
            "ML",
            "Sets Handicap",
            "O/U"
        ]
    ]
  ]
]

使用json_encode它应该非常简单。

http://php.net/manual/en/function.json-encode.php