我目前正在为spotify api构建一个前端。spotify api会返回这些结果。 我只想解析“id”、“name”和“artist”…我是一个新手,请帮忙我怎么做
"messageCode":200,"result":{"imageurl":"http:\/\/example.com","data":[{"id":101,"name":"","type":"Dynamic","seeall":false,"vertical":false,"list":[]},{"id":"8_121","name":"Weekly Top 20","type":"songs","seeall":true,"vertical":false,"section_id":"26","list":[{"id":"1801_1800323_7","title":"Se\u00f1orita","artist":"Shawn Mendes,Camila Cabello","subtitle":"Shawn Mendes","image":"1801\/1800323\/1800323_1564237811_200x200.jpg","type":"songs","albumid":"1800323"},{"id":"1696_1695386_1","title":"On My Way","artist":"Alan Walker,Sabrina Carpenter,Farruko","subtitle":"On My Way","image":"1696\/1695386\/1695386_1552085406_200x200.jpg","type":"songs","albumid":"1695386"},{"id":"1840_1839953_1","title":"Memories","artist":"Maroon 5","subtitle":"Memories","image":"1840\/1839953\/1839953_1569036611_200x200.jpg","type":"songs","albumid":"1839953"},{"id":"1889_1888580_1","title":"Ahimsa","artist":"U2,A.R Rahman","subtitle":"Ahimsa","image":"1889\/1888580\/1888580_1574289013_200x200.jpg","type":"songs","albumid":"1888580"},{"id":"1712_1711742_1","title":"Sugar & Brownies","artist":"Dharia","subtitle":"Sugar & Brownies","image":"1712\/1711742\/1711742_1553572206_200x200.jpg","type":"songs","albumid":"1711742"},{"id":"1787_1786076_1","title":"Beautiful People (feat. Khalid)","artist":"Ed Sheeran, Khalid","subtitle":"Beautiful People (feat. Khalid)","image":"1787\/1786076\/1786076_1562329809_200x200.jpg","type":"songs","albumid":"1786076"},{"id":"1845_1844331_1","title":"Lean On","artist":"Celina Sharma,Emiway Bantai","subtitle":"Lean On","image":"1845\/1844331\/1844331_1569490212_200x200.jpg","type":"songs","albumid":"1844331"},{"id":"1871_1870887_1","title":"Lose You To Love Me","artist":"Selena Gomez","subtitle":"Lose You To Love Me","image":"1871\/1870887\/1870887_1572291013_200x200.jpg","type":"songs","albumid":"1870887"},
问题来源StackOverflow 地址:/questions/59387135/parse-stuff-within-curly-brackets
把上面这个 JSON 字符串传递到前端就很容易了: let jret = JSON.parse('xxxx'); //xxx 就是你的返回内容 然后就很容易了: let dataArr = jret["result"]["data"]; 就拿到 data 数组了 dataArr[0]["id"] 就拿到第一个的 id 了
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。