PHP-求指教下这段JSON怎么转成PHP数组

发布于 2017-01-21 19:32:19 字数 2339 浏览 1210 评论 1

OR.C[10]([{"children":[{"parent_id":19,"landing_pv_times":438,"src_name":"淘宝站内其他","src_id":59},{"parent_id":19,"landing_pv_times":120,"src_name":"淘宝搜索","src_id":20},{"parent_id":19,"landing_pv_times":106,"src_name":"商城频道","src_id":39},{"parent_id":19,"landing_pv_times":93,"src_name":"商城搜索","src_id":36},{"parent_id":19,"landing_pv_times":8,"src_name":"阿里旺旺非广告","src_id":32},{"parent_id":19,"landing_pv_times":5,"src_name":"淘宝店铺搜索","src_id":21},{"parent_id":19,"landing_pv_times":5,"src_name":"淘宝类目","src_id":22},{"parent_id":19,"landing_pv_times":4,"src_name":"店铺动态","src_id":45},{"parent_id":19,"landing_pv_times":2,"src_name":"淘宝信用评价","src_id":31},{"parent_id":19,"landing_pv_times":1,"src_name":"试用中心","src_id":44}],"landing_pv_times":782,"src_name":"淘宝免费流量","src_id":19},{"children":[{"parent_id":1,"landing_pv_times":210,"src_name":"直接访问","src_id":6},{"parent_id":1,"landing_pv_times":73,"src_name":"我的淘宝","src_id":5},{"parent_id":1,"landing_pv_times":20,"src_name":"购物车","src_id":7},{"parent_id":1,"landing_pv_times":18,"src_name":"店铺收藏","src_id":2},{"parent_id":1,"landing_pv_times":10,"src_name":"宝贝收藏","src_id":3},{"parent_id":1,"landing_pv_times":2,"src_name":"卖家中心","src_id":4}],"landing_pv_times":333,"src_name":"自主访问","src_id":1},{"children":[{"parent_id":8,"landing_pv_times":38,"src_name":"淘宝客","src_id":10}],"landing_pv_times":38,"src_name":"淘宝付费流量","src_id":8},{"children":[{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http%3A%2F%2Fweibo.com%2Fsssurman%3Fwvr%3D3.6%26lf%3Dreg","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http://e.weibo.com/tmall?page&pre_page=6&end_id=3517474811393427&page=5","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http%3A%2F%2Fs.weibo.com%2Fweibo%2F%2525E5%2525A4%2525A9%2525E7%25258C%2525AB%2525E9%2525A2%","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/3052375242/profile?ref=http%3A%2F%2Fe.weibo.com%2Fjiayimeijiaju%3Ftopnav%3D11","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://h2w.iask.cn/jump.php?url=http%3A%2F%2Fdetail.tmall.com%2Fitem.htm%3Fspm%3Da1z10.3.0.64.LffHzC%26id%3D17532067147%26%26sh","src_id":-1}],"landing_pv_times":5,"src_name":"淘宝站外其他","src_id":74}]);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2017-10-03 23:51:29

<?php
$str =<<<EOF
OR.C[10]([{"children":[{"parent_id":19,"landing_pv_times":438,"src_name":"淘宝站内其他","src_id":59},{"parent_id":19,"landing_pv_times":120,"src_name":"淘宝搜索","src_id":20},{"parent_id":19,"landing_pv_times":106,"src_name":"商城频道","src_id":39},{"parent_id":19,"landing_pv_times":93,"src_name":"商城搜索","src_id":36},{"parent_id":19,"landing_pv_times":8,"src_name":"阿里旺旺非广告","src_id":32},{"parent_id":19,"landing_pv_times":5,"src_name":"淘宝店铺搜索","src_id":21},{"parent_id":19,"landing_pv_times":5,"src_name":"淘宝类目","src_id":22},{"parent_id":19,"landing_pv_times":4,"src_name":"店铺动态","src_id":45},{"parent_id":19,"landing_pv_times":2,"src_name":"淘宝信用评价","src_id":31},{"parent_id":19,"landing_pv_times":1,"src_name":"试用中心","src_id":44}],"landing_pv_times":782,"src_name":"淘宝免费流量","src_id":19},{"children":[{"parent_id":1,"landing_pv_times":210,"src_name":"直接访问","src_id":6},{"parent_id":1,"landing_pv_times":73,"src_name":"我的淘宝","src_id":5},{"parent_id":1,"landing_pv_times":20,"src_name":"购物车","src_id":7},{"parent_id":1,"landing_pv_times":18,"src_name":"店铺收藏","src_id":2},{"parent_id":1,"landing_pv_times":10,"src_name":"宝贝收藏","src_id":3},{"parent_id":1,"landing_pv_times":2,"src_name":"卖家中心","src_id":4}],"landing_pv_times":333,"src_name":"自主访问","src_id":1},{"children":[{"parent_id":8,"landing_pv_times":38,"src_name":"淘宝客","src_id":10}],"landing_pv_times":38,"src_name":"淘宝付费流量","src_id":8},{"children":[{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http%3A%2F%2Fweibo.com%2Fsssurman%3Fwvr%3D3.6%26lf%3Dreg","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http://e.weibo.com/tmall?page&pre_page=6&end_id=3517474811393427&page=5","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/tmallyushou?ref=http%3A%2F%2Fs.weibo.com%2Fweibo%2F%2525E5%2525A4%2525A9%2525E7%25258C%2525AB%2525E9%2525A2%","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://e.weibo.com/3052375242/profile?ref=http%3A%2F%2Fe.weibo.com%2Fjiayimeijiaju%3Ftopnav%3D11","src_id":-1},{"parent_id":74,"landing_pv_times":1,"src_name":"http://h2w.iask.cn/jump.php?url=http%3A%2F%2Fdetail.tmall.com%2Fitem.htm%3Fspm%3Da1z10.3.0.64.LffHzC%26id%3D17532067147%26%26sh","src_id":-1}],"landing_pv_times":5,"src_name":"淘宝站外其他","src_id":74}]);
EOF;

//去掉掉 OR.C[10]( 和 );
$str = substr($str, strpos($str, '(') + 1, -(strlen($str) - strrpos($str, ')')));

// json_decode
$str = json_decode($str, true);

print_r($str);

看效果

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文