gpt4 book ai didi

javascript - 如何访问下面的 json 值

转载 作者:行者123 更新时间:2023-11-30 19:05:21 25 4
gpt4 key购买 nike

您好,我正在尝试访问值 DepartmentId,但由于值不存在而出现错误。

当我尝试访问 DepartmentId 时,我可以获得大括号内的值,但出现错误。

下面是我的 map 函数

 r.PrimarySearchResults.map((value) => {
console.log(value)}
)

我可以得到 value.Rank 但不能得到 value.DepartmentId

下面是我得到的JSON对象。这是我展开对象的时候。

{Rank: "16.9111518859863", DocId: 
"17598046715456", Title: "HubSite", SPSiteUrl: "https://amoghtelkar.sharepoint.com/sites/hubsite2",
WebTemplate: "SITEPAGEPUBLISHING", …}
Culture: "en-US"
DepartmentId: "{3d408bfe-9172-4df5-b36e-863c066e9ada}"
DocId: "17598046715456"
PartitionId: "51ddbb65-42e8-4906-82e4-8d97c6626ef7"
Rank: "16.9111518859863"
RenderTemplateId: "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js"
ResultTypeId: "0"
SPSiteUrl: "https://amoghtelkar.sharepoint.com/sites/hubsite2"
SiteId: "3d408bfe-9172-4df5-b36e-863c066e9ada"
Title: "HubSite"
UniqueId: "{F08C7BCE-C886-4A09-AA22-D66879DD5252}"
UrlZone: "0"
WebId: "edec632a-5671-49bd-a7fe-27a6e851f09a"
WebTemplate: "SITEPAGEPUBLISHING"
__proto__: Object

找到下面的图片 Please find the image

最佳答案

尝试安排您的 JSON 对象,似乎 DepartmentId 不包含在 JSON 中

{
Rank: "16.9111518859863",
DocId: "17598046715456",
Title: "HubSite",
SPSiteUrl: "https://amoghtelkar.sharepoint.com/sites/hubsite2",
WebTemplate: "SITEPAGEPUBLISHING", }

Culture: "en-US" DepartmentId: "{3d408bfe-9172-4df5-b36e-863c066e9ada}" DocId: "17598046715456" PartitionId: "51ddbb65-42e8-4906-82e4-8d97c6626ef7" Rank: "16.9111518859863" RenderTemplateId: "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js" ResultTypeId: "0" SPSiteUrl: "https://amoghtelkar.sharepoint.com/sites/hubsite2" SiteId: "3d408bfe-9172-4df5-b36e-863c066e9ada" Title: "HubSite" UniqueId: "{F08C7BCE-C886-4A09-AA22-D66879DD5252}" UrlZone: "0" WebId: "edec632a-5671-49bd-a7fe-27a6e851f09a" WebTemplate: "SITEPAGEPUBLISHING"

试试这个:

var value = JSON.parse(value);console.log(value.DepartmentId);

关于javascript - 如何访问下面的 json 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59044102/

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