首页 > Nodejs中如何处理服务器返回的JS语句?

Nodejs中如何处理服务器返回的JS语句?

调用淘宝的手机号归属地查询
http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443
返回结果是这样的

__GetZoneResult_ = {
    mts:'1585078',
    province:'江苏',
    catName:'中国移动',
    telString:'15850781443',
    areaVid:'30511',
    ispVid:'3236139',
    carrier:'江苏移动'
}

请问这个结果在Nodejs中应该如何处理?


把花括号外的字符去掉,用JSON.parse


这个直接url给script标签的src,结果放到script标签里不就好了么...


这不就是JSON嘛? 不对... 是JS来的...
那给ta个执行的环境吧

jsStr = "__GetZoneResult_ = { foo:'bar' }"
eval(jsStr)
console.log(__GetZoneResult_) //=> { foo:'bar' }

亲测有效

【热门文章】
【热门文章】