请教各位关于php正则匹配截取json 语句的问题-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

请教各位关于php正则匹配截取json 语句的问题

落地花开啦 2016-06-15 10:21:54 1283

请教一个正则截取问题

$script='<script type="text/javascript">
cgiData={
pageIdx : 0,
pageCount : 1,
pageSize : 100,
groupsList : ({"groups":[{"id":0,"name":"未分组","cnt":16},{"id":1,"name":"黑名单","cnt":0},{"id":2,"name":"星标组","cnt":0}]}).groups,
        friendsList : ({"contacts":[{"id":6,"nick_name":"yan","remark_name":"","group_id":0},{"id":8,"nick_name":"mm","remark_name":"","group_id":0},{"id":4,"nick_name":"gg","remark_name":"","group_id":0},{"id":2,"nick_name":"sa","remark_name":"","group_id":0}]}).contacts,
            currentGroupId : 0,
        type : 0,
    userRole : 1 * 1,
    verifyMsgCount :  * 1
};
seajs.use("user/index");
</script>';

怎么把contacts中间的
[{"id":6,"nickname":"yan","remarkname":"","groupid":0},{"id":8,"nickname":"mm","remarkname":"","groupid":0},{"id":4,"nickname":"gg","remarkname":"","groupid":0},{"id":2,"nickname":"sa","remarkname":"","groupid":0}]
这段截取出来?

JSON PHP 数据格式
分享到
取消 提交回答
全部回答(1)
  • 落地花开啦
    2019-07-17 19:38:47

    (?<="contacts"\:\[){.*}(?=\].*\.contacts)

    注:PHP里好像需要把"转义一下变成"

    0 0

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程