gpt4 book ai didi

javascript - 如何解析[object对象]

转载 作者:行者123 更新时间:2023-11-28 17:50:04 38 4
gpt4 key购买 nike

我不知道如何解析响应中的值。我需要根据各个字符串中的键和值获取值,但无法使其工作

这是我的示例代码

[
{"columns":
["campName","page_visits","filter_types","searchUrl","pageNo"],
"values":[["kk","2","All","https://www.google.com/search/results/people/?keywords=kk&origin=SWITCH_SEARCH_VERTICAL",1]]}]

我想要 campNamepage_visitsfilter_typessearchUrlpageNo 值在 javascript 中存储为字符串

最佳答案

您可以将这些值存储在一个对象中:

const data = [{
"columns": ["campName", "page_visits", "filter_types", "searchUrl", "pageNo"],
"values": [
["kk", "2", "All", "https://www.google.com/search/results/people/?keywords=kk&origin=SWITCH_SEARCH_VERTICAL", 1]
]
}]

const result = data[0].columns.reduce((acc, curr, index) => {
acc[curr] = data[0].values[0][index];

return acc;
}, {});

console.log(result);

关于javascript - 如何解析[object对象],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45734809/

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