使用正则获取jsonp字符串里的json数据

定义一个正则表达式:

var reg = /^\w+\(({[^()]+})\)$/
var mstches = ret.match(reg)
if(matches){
    ret = JSON.parse(matches[1]) 
    // matches[0]为整个字符串
    // matches[1]为匹配到的分组
}
posted @ 2019-03-07 15:27  zllmh  阅读(5034)  评论(0编辑  收藏  举报