采集微信平台实时消息json问题 微信平台采集回来的json字符通过json_decode转换为null.如果直接把结果放到json_decode中是可以转换的。微信JSON 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $url="https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&".$token."&lang=zh_CN&count=50&timeline=1&day=0";$ch = curl_init($url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);$contents = curl_exec($ch);preg_match("/<script type=\"json\" id=\"json-msgList\">([\s+].*)/s",$contents,$json);curl_close($ch);$str = '[ {"id":"295","type":"3","fileId":"0","hasReply":"0","fakeId":"2121212121","nickName":"哈哈哈","reName":"","dateTime":"1374114620","icon":"","content":"","playLength":"5505","length":"3696","source":"","starred":"0","status":"4","subtype":"0","showType":"0","desc":"","title":"","appName":"","contentUrl":"","bcardNickName":"","bcardUserName":"","bcardFakeId":"0"} ]';print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示print_r(json_decode($json[1]));//直接用匹配到的数据则显示为null $url="https://mp.weixin.qq.com/cgi-bin/getmessage?t=wxm-message&".$token."&lang=zh_CN&count=50&timeline=1&day=0";$ch = curl_init($url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);$contents = curl_exec($ch);preg_match("/<script type=\"json\" id=\"json-msgList\">([\s+].*)/s",$contents,$json);curl_close($ch);$str = '[ {"id":"295","type":"3","fileId":"0","hasReply":"0","fakeId":"2121212121","nickName":"哈哈哈","reName":"","dateTime":"1374114620","icon":"","content":"","playLength":"5505","length":"3696","source":"","starred":"0","status":"4","subtype":"0","showType":"0","desc":"","title":"","appName":"","contentUrl":"","bcardNickName":"","bcardUserName":"","bcardFakeId":"0"} ]';print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示print_r(json_decode($json[1]));//直接用匹配到的数据则显示为null 由于涉及到隐私,不好向你索取隐去的数据。自然就不能运行你的代码但你总可以贴出 $json 的值吧print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示你在浏览器“查看网页源代码”中得到的也可以转码?双引号被转义了吧? 浏览器打印出来的json的值我已经贴出来了就是保存在$str变量里。查看源码发现多了好多没用的东西?<script type="text/javascript">window.WXM && (function(WXM, win){ var DATA = WXM.DATA; DATA.title = "实时消息"; DATA.catalogList = [ { title : "全部消息", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50', subCatalogList : 0 } ,{ _id : 'msgNavCur', title : "今天", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=0', subCatalogList : 'subCatalogList' } ,{ title : "昨天", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=1', subCatalogList : 'subCatalogList' } ,{ title : "前天", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=2', subCatalogList : 'subCatalogList' } ,{ title : "5天内消息", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=3', subCatalogList : 'subCatalogList' } , { title : "星标消息", link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&star=1', subCatalogList : '' } ]; DATA.List = {}; DATA.List.keyword = ''; DATA.List.keyword && (DATA.List.keyword = DATA.List.keyword.replace(/</g, '<').replace(/>/g,'>')); DATA.List.count = '50'*1; DATA.List.day = '0'; DATA.List.timeline = '1'; DATA.List.star = ''; DATA.List.totalMsgNum = '6' * 1; DATA.List.pageNav = { PageIdx : '0'*1, PageCount : '1'*1, passPage:'', nextPage:'', pageJump:false, baseurl : '' }; DATA.List.msgList = jQuery.parseJSON(jQuery('#json-msgList').html()); DATA.lastMsgId = '300';})(WXM, window);</script><script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-msg-op16aa22.js"></script><script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-swfobject15def8.js"></script><script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-media15def8.js"></script><script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-message15def8.js"></script><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/mpres/htmledition/style/wxm_media15def8.css"/> 你贴出的不是 html 代码吗?你说的 json 数据在哪里?由 js 动态读取的? 源码里多了这些东西,我发现我正则匹配错了。如果我要匹配<script type="json" id="json-msgList"></script>中的内容应该怎么写? preg_match("/<script type=\"json\" id=\"json-msgList\">(.+?)<\/script>/s",$contents,$json); Web编程常用手册下载 为什么要用PHP来开发网站? 网页上直播实况视屏怎么做 求php和mysql web开发第四版的代码 学习phpcms开源产品怎么入手 求一个ISAPI_Rewrite的写法 求问MYSQL 建数据库思路 有点乱 php 程序员使用是什么linux系统好呢?? php导出mysql数据库文件 PHP银联手机在线支付 php短信接口 还原加密!高分!
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<script type=\"json\" id=\"json-msgList\">([\s+].*)/s",$contents,$json);
curl_close($ch);
$str = '[ {"id":"295","type":"3","fileId":"0","hasReply":"0","fakeId":"2121212121","nickName":"哈哈哈","reName":"","dateTime":"1374114620","icon":"","content":"","playLength":"5505","length":"3696","source":"","starred":"0","status":"4","subtype":"0","showType":"0","desc":"","title":"","appName":"","contentUrl":"","bcardNickName":"","bcardUserName":"","bcardFakeId":"0"} ]';
print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示
print_r(json_decode($json[1]));//直接用匹配到的数据则显示为null
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<script type=\"json\" id=\"json-msgList\">([\s+].*)/s",$contents,$json);
curl_close($ch);
$str = '[ {"id":"295","type":"3","fileId":"0","hasReply":"0","fakeId":"2121212121","nickName":"哈哈哈","reName":"","dateTime":"1374114620","icon":"","content":"","playLength":"5505","length":"3696","source":"","starred":"0","status":"4","subtype":"0","showType":"0","desc":"","title":"","appName":"","contentUrl":"","bcardNickName":"","bcardUserName":"","bcardFakeId":"0"} ]';
print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示
print_r(json_decode($json[1]));//直接用匹配到的数据则显示为null
但你总可以贴出 $json 的值吧print_r(json_decode($str)); //如果直接转浏览器上的json数据可以显示
你在浏览器“查看网页源代码”中得到的也可以转码?
双引号被转义了吧?
window.WXM && (function(WXM, win){
var DATA = WXM.DATA;
DATA.title = "实时消息";
DATA.catalogList = [
{
title : "全部消息",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50',
subCatalogList : 0
}
,{
_id : 'msgNavCur',
title : "今天",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=0',
subCatalogList : 'subCatalogList'
}
,{
title : "昨天",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=1',
subCatalogList : 'subCatalogList'
}
,{
title : "前天",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=2',
subCatalogList : 'subCatalogList'
}
,{
title : "5天内消息",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&timeline=1&day=3',
subCatalogList : 'subCatalogList'
}
,
{
title : "星标消息",
link : '/cgi-bin/getmessage?t=wxm-message&token=466153210&lang=zh_CN&count=50&star=1',
subCatalogList : ''
}
];
DATA.List = {};
DATA.List.keyword = '';
DATA.List.keyword && (DATA.List.keyword = DATA.List.keyword.replace(/</g, '<').replace(/>/g,'>'));
DATA.List.count = '50'*1;
DATA.List.day = '0';
DATA.List.timeline = '1';
DATA.List.star = '';
DATA.List.totalMsgNum = '6' * 1;
DATA.List.pageNav = {
PageIdx : '0'*1,
PageCount : '1'*1,
passPage:'',
nextPage:'',
pageJump:false,
baseurl : ''
}; DATA.List.msgList = jQuery.parseJSON(jQuery('#json-msgList').html());
DATA.lastMsgId = '300';
})(WXM, window);
</script><script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-msg-op16aa22.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-swfobject15def8.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-media15def8.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/mpres/zh_CN/htmledition/js/wxm-message15def8.js"></script><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/mpres/htmledition/style/wxm_media15def8.css"/>
你说的 json 数据在哪里?由 js 动态读取的?