gpt4 book ai didi

javascript - 如何在 JSON.stringify() 之后获取特定值

转载 作者:行者123 更新时间:2023-12-03 16:48:09 24 4
gpt4 key购买 nike

这是console.log中显示的数据。

{"data":
[
{
"CloserName":null,
"agent_id":"10807",
"AgentName":"TEST",
"SurveyDate":"02/02/2018 02:18:46 AM",
"SurveyName":"Ruth ",
"state":"West Bengal",
"phone":"9836969715",
"status":"Approved",
"verification_progress":"Pending",
"survey_id":"1",
"rejection_remarks":"aa",
"tl_remarks":"Pending"
}
],
"count":1
}

谁能帮我显示一个值(即survey_id)?我只想获取那个 survey_id

最佳答案

这是一个例子:

var json = {  
"data":[
{
"CloserName":null,
"agent_id":"10807",
"AgentName":"TEST",
"SurveyDate":"02/02/2018 02:18:46 AM",
"SurveyName":"Ruth ",
"state":"West Bengal",
"phone":"9836969715",
"status":"Approved",
"verification_progress":"Pending",
"survey_id":"1",
"rejection_remarks":"aa",
"tl_remarks":"Pending"
}
],
"count":1
}

// get first id
var id = json.data[0].survey_id
console.log(id)

// get all ids
var ids = json.data.map(x => x.survey_id)
console.log(ids)

如果 JSON 是字符串化的,请先调用 JSON.parse(jsonStr)

关于javascript - 如何在 JSON.stringify() 之后获取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48680112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com