微信开发 返回json数据 提取元素问题
在微信开发中,获取用户信息开发中,返回了如下的json数据:string(311)"{"subscribe":1,"openid":"oEGx2jhJLGSNo9aqKC...
在微信开发中,获取用户信息开发中,返回了如下的json数据:
string(311) "{"subscribe":1,"openid":"oEGx2jhJLGSNo9aqKCcIt_qAtW4Y","nickname":"七哥","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/sD8VfYHsSCYWnib7kamBicUO4c0wBKnTAc5u7jySgwC6nlWrprFfLocOl6JnnvkibXdgia3Qfw4uUmRO4Vd8989MclsKJg3mKrYv/0","subscribe_time":1383839530}"
怎么提取headimgurl元素的值呢?老是出错! 展开
string(311) "{"subscribe":1,"openid":"oEGx2jhJLGSNo9aqKCcIt_qAtW4Y","nickname":"七哥","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/sD8VfYHsSCYWnib7kamBicUO4c0wBKnTAc5u7jySgwC6nlWrprFfLocOl6JnnvkibXdgia3Qfw4uUmRO4Vd8989MclsKJg3mKrYv/0","subscribe_time":1383839530}"
怎么提取headimgurl元素的值呢?老是出错! 展开
展开全部
你需要把string转换成json的object
var string = "{"subscribe":1,"openid":"oEGx2jhJLGSNo9aqKCcIt_qAtW4Y","nickname":"七哥","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/sD8VfYHsSCYWnib7kamBicUO4c0wBKnTAc5u7jySgwC6nlWrprFfLocOl6JnnvkibXdgia3Qfw4uUmRO4Vd8989MclsKJg3mKrYv/0","subscribe_time":1383839530}"
var data = jQuery.parseJSON(string);
var headimgurl = data.headimgurl;
var string = "{"subscribe":1,"openid":"oEGx2jhJLGSNo9aqKCcIt_qAtW4Y","nickname":"七哥","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/sD8VfYHsSCYWnib7kamBicUO4c0wBKnTAc5u7jySgwC6nlWrprFfLocOl6JnnvkibXdgia3Qfw4uUmRO4Vd8989MclsKJg3mKrYv/0","subscribe_time":1383839530}"
var data = jQuery.parseJSON(string);
var headimgurl = data.headimgurl;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询