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中应该如何处理?

request node.js JavaScript 归属地

撸了.Null 10 years, 10 months ago

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

腐腐腐腐腐 answered 10 years, 10 months ago

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

薇薇如此机智 answered 10 years, 10 months ago

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


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

亲测有效

反魂蝶8分咲 answered 10 years, 10 months ago

Your Answer