console.log(res.result)打印值如下:
"{"images":[{"startdate":"20210509","fullstartdate":"202105091600","enddate":"20210510","url":"/th?id=OHR.TulpenMiesbach_ZH-CN8593652929_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.TulpenMiesbach_ZH-CN8593652929","copyright":"米斯巴赫的郁金香田,德国巴伐利亚州 ( Rüdiger Hess/geo-select FotoArt)","copyrightlink":"https://www.bing.com/search?q=%E9%83%81%E9%87%91%E9%A6%99&form=hpcapt&mkt=zh-cn","title":"","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20210509_TulpenMiesbach%22&FORM=HPQUIZ","wp":true,"hsh":"f6dcca1a0c4af911aa69a3dda148f3b9","drk":1,"top":1,"bot":1,"hs":[]}],"tooltips":{"loading":"正在加载...","previous":"上一个图像","next":"下一个图像","walle":"此图片不能下载用作壁纸。","walls":"下载今日美图。仅限用作桌面壁纸。"}}"
console.log(res.result.images[0])显示
Cannot read property '0' of undefined
我如何提取url的值?
JSON.parse +1
楼上两位都没说到点子上,json.parse确实可以,但是不够优雅。
请求的时候,添加
dataType
参数为json,就自动parse了参考文档:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
JSON.parse