javascript - 非标准json格式解析的问题

WBOY
Release: 2016-07-06 13:52:59
Original
2263 people have browsed it

1.

javascript - 非标准json格式解析的问题

返回的是这个格式,PHP的json_decode();不能直接解析,难道要各种切割字符串成JSON格式,在用json_decode();解析?

javascript - 非标准json格式解析的问题

这是标准的json格式.

2.
javascript - 非标准json格式解析的问题
这个特别接近json格式了,但是还是无法解析.
各位有没有好的方法.

回复内容:

1.

javascript - 非标准json格式解析的问题

返回的是这个格式,PHP的json_decode();不能直接解析,难道要各种切割字符串成JSON格式,在用json_decode();解析?

javascript - 非标准json格式解析的问题

这是标准的json格式.

2.
javascript - 非标准json格式解析的问题
这个特别接近json格式了,但是还是无法解析.
各位有没有好的方法.

这里是 是不是 的问题
而不是 像不像 的问题

老老实实把提取出来吧。

<code class="php">$res = file_get_contents('https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15011923452');
    /*"__GetZoneResult_ = {
    mts:'1501192',
    province:'广东',
    catName:'中国移动',
    telString:'15011923452',
    areaVid:'30517',
    ispVid:'3236139',
    carrier:'广东移动'
}"*/
    $res = trim(explode('=',$res)[1]);
    $res = iconv('gbk','utf-8', $res);
    $res = str_replace("'",'"', $res);
    $res = preg_replace('/(\w+):/is', '"$1":', $res);
    print_r(json_decode($res,1));
    /*Array
(
    [mts] => 1501192
    [province] => 广东
    [catName] => 中国移动
    [telString] => 15011923452
    [areaVid] => 30517
    [ispVid] => 3236139
    [carrier] => 广东移动
)*/</code>
Copy after login

PHP的话必须要提取成json字符串才行。。

这是个js的属性对象吧...
如果不怕XSS注入的风险,可以直接扔到js里面。

全部取出来=>用正则去掉第一个{前的内容=>JSON.parse

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!