好吧,我脑子放屁了。我需要如下所述提取“数据”的值...
const d.body = {"data":[{"id":"30220059","login":"esl_sc2","display_name":"ESL_SC2","type":"","broadcaster_type":"合作伙伴","description":"有关积分榜、赛程表和结果,请访问 https://pro.eslgaming.com/tour/sc2/","profile_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures /cac110f7-0711-421f-9341-c77b53ab63b5-profile_image-300x300.jpeg","offline_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures/ac0e240d-63c2-4faf-9040-60543b3e2c0f-channel _offline_image-1920x1080 .jpeg","view_count":0,"created_at":"2012-05-02T09:59:20Z"}]}
javaScript 需要对“d.body”执行什么操作才能使输出看起来像这样......
{"id":"30220059","login":"esl_sc2","display_name":"ESL_SC2","type":"","broadcaster_type":"partner","description":"查看排名、时间表和结果,请访问 https://pro.eslgaming.com/tour/sc2/","profile_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures/cac110f7-0711-421f-9341-c77b53ab63b5 -profile_image-300x300.jpeg","offline_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures/ac0e240d-63c2-4faf-9040-60543b3e2c0f-channel_offline_image-1920x1080.jpeg","view_count":0, “created_at”:“2012-05-02T09:59:20Z”}
我以为只是 d.body.data[0]?
您可以使用以下解构赋值直接获取 json
let { data: [data = {}] = [0] } = {
"data":[
{
"id":"30220059",
"login":"esl_sc2",
"display_name":"ESL_SC2",
"type":"",
"broadcaster_type":"partner",
"description":"For standings, schedule, and results, visit https://pro.eslgaming.com/tour/sc2/",
"profile_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures/cac110f7-0711-421f-9341-c77b53ab63b5-profile_image-300x300.jpeg",
"offline_image_url":"https://static-cdn.jtvnw.net/jtv_user_pictures/ac0e240d-63c2-4faf-9040-60543b3e2c0f-channel_offline_image-1920x1080.jpeg",
"view_count":0,
"created_at":"2012-05-02T09:59:20Z"
}
]
}
console.log(data)