我試圖通過這個(gè) JSON 對(duì)象并從中獲取一些值。let currentPage = "{ "sys": { "space": { "sys": { "type": "Link", "linkType": "Space", "id": "xaswoie0ncrg" } }, "id": "7lqAYzwP92G9TMDBUVnadp", "type": "Entry", "createdAt": "2020-07-30T18:08:33.159Z", "updatedAt": "2020-07-30T18:22:50.276Z", "environment": { "sys": { "id": "master", "type": "Link", "linkType": "Environment" } }, "revision": 2, "contentType": { "sys": { "type": "Link", "linkType": "ContentType", "id": "landingPage" } }, "locale": "en-US" }, "fields": { "pageTitle": "Leading the next generation of renewable fuels", "heroImage": { "sys": { "type": "Link", "linkType": "Asset", "id": "vnjfnYzSyhqOjKlmNmBGb" } }, "pageZone": [ { "sys": { "type": "Link", "linkType": "Entry", "id": "3aQvORUYowW0SoofuvHUov" } }, { "sys": { "type": "Link", "linkType": "Entry", "id": "Qfj1hNJ9euSkBcAQEDaN5" } } ] }}"然后我解析 JSON:let currentPage2 = JSON.parse(currentPage); 現(xiàn)在問題來了。如果將此記錄在控制臺(tái)中:console.log(Object.keys(currentPage2.fields.pageZone[0].sys.id)); 節(jié)點(diǎn)在終端中返回這個(gè):[ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21']我想用這個(gè):console.log(Object.keys(currentPage2.fields.pageZone[0].sys.id).value);//with expected value of "3aQvORUYowW0SoofuvHUov"相反,它返回undefined。我不知道為什么會(huì)這樣。我試過使用JSON.stringifyetc 并再次解析它,但它仍然以這種方式運(yùn)行。
JSON 返回一個(gè)數(shù)字?jǐn)?shù)組,而不是 JSON 中對(duì)象中的值
神不在的星期二
2022-12-22 10:54:50