JavaScript-non-standard JSON format parsing issues

Source: Internet
Author: User

1.

Return is this format, PHP json_decode (), not directly parse, should be a variety of cutting string into JSON format, in the use of Json_decode ();

This is the standard JSON format.

2.

This is particularly close to the JSON format, but it is still unresolved.
You have a good way.

Reply content:

1.

Return is this format, PHP json_decode (), not directly parse, should be a variety of cutting string into JSON format, in the use of Json_decode ();

This is the standard JSON format.

2.

This is particularly close to the JSON format, but it is still unresolved.
You have a good way.

This is not the problem
Not like a problem.

Get it out honestly.

$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] => 广东移动)*/

PHP words must be extracted into a JSON string before the line.

This is a JS Property object ...
If you are not afraid of the risk of XSS injection, you can throw it directly into JS.

Take it all out, and remove the first {before you use a regular =>json.parse

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.