今天我需要你的帮助来转换一个字符串(我将其命名为$ data),如下所示:
{"hours":{"2018-06-10 11:00":2,"2018-06-12 07:00":5,"2018-06-12 08:00":4,"2018-06-12 09:00":2,"2018-06-13 09:00":1,"2018-06-13 13:00":1,"2018-06-13 23:00":1,"2018-06-15 13:00":1,"2018-06-15 14:00":1,"2018-06-15 15:00":2,"2018-06-18 06:00":5,"2018-06-18 07:00":9,"2018-06-18 08:00":1,"2018-06-18 09:00":1,"2018-06-18 12:00":2,"2018-06-18 13:00":13},"days":{"2018-06-10 00:00":2,"2018-06-12 00:00":11,"2018-06-13 00:00":3,"2018-06-15 00:00":4,"2018-06-18 00:00":29,"2018-06-18 07:00":2},"weeks":{"2018-06-10 00:00":20,"2018-06-17 00:00":29,"2018-06-18 07:00":2}}
这样的事情:
我知道有一些PHP函数,比如str_split或explode,但我真的不知道怎么做。 我试图做出类似的事情:
explode('{', $data);
或类似的东西,但我真的不知道从哪里开始,如果我用“:”爆炸,它也将在日期中使用“:”。
如果我忘记放东西,请告诉我我会编辑问题。
提前致谢
答案 0 :(得分:1)
或者你可以试试这个:
$data = '{"hours":{"2018-06-10 11:00":2,"2018-06-12 07:00":5,"2018-06-12 08:00":4,"2018-06-12 09:00":2,"2018-06-13 09:00":1,"2018-06-13 13:00":1,"2018-06-13 23:00":1,"2018-06-15 13:00":1,"2018-06-15 14:00":1,"2018-06-15 15:00":2,"2018-06-18 06:00":5,"2018-06-18 07:00":9,"2018-06-18 08:00":1,"2018-06-18 09:00":1,"2018-06-18 12:00":2,"2018-06-18 13:00":13},"days":{"2018-06-10 00:00":2,"2018-06-12 00:00":11,"2018-06-13 00:00":3,"2018-06-15 00:00":4,"2018-06-18 00:00":29,"2018-06-18 07:00":2},"weeks":{"2018-06-10 00:00":20,"2018-06-17 00:00":29,"2018-06-18 07:00":2}}
';
$dados = json_decode( $data, true );
echo "<pre>";
print_r($dados);
echo "</pre>";
答案 1 :(得分:0)
这里试试这个:
$json = '{"hours":
{"2018-06-10 11:00":2,"2018-06-12 07:00":5,"2018-06-12 08:00":4,"2018-06-12 09:00":2,"2018-06-13 09:00":1,"2018-06-13 13:00":1,"2018-06-13 23:00":1,"2018-06-15 13:00":1,"2018-06-15 14:00":1,"2018-06-15 15:00":2,"2018-06-18 06:00":5,"2018-06-18 07:00":9,"2018-06-18 08:00":1,"2018-06-18 09:00":1,"2018-06-18 12:00":2,"2018-06-18 13:00":13},
"days":{"2018-06-10 00:00":2,"2018-06-12 00:00":11,"2018-06-13 00:00":3,"2018-06-15 00:00":4,"2018-06-18 00:00":29,"2018-06-18 07:00":2},"weeks":{"2018-06-10 00:00":20,"2018-06-17 00:00":29,"2018-06-18 07:00":2}
}';
$toarray = json_decode($json, true);