json - Not able to read values through Graph API JSON response
问题描述
I'm trying to get "values" (both id and name of each element) from the Graph API JSON response below using Object.keys but not able to retrieve the exact values.
JSON Response
-----------------------------------------------------------------------------------------------
Site Lists Results: {"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#drives(id,name)","value":[{"id":"b!pHlD_lSxbkCozGQrFbrTmcaLJVe3f09MnccP5vDr3Q5y_50YoNRJSqWRyeKBbOqh","name":"Documents"},{"id":"b!pHlD_lSxbkCozGQrFbrTmcaLJVe3f09MnccP5vDr3Q4wPyFW_1gbSYPGhq8-0_6b","name":"SPFx Image Rotator"}]}
const results = await this.spService.getSiteLists(this.properties.siteUrl);
console.log("Site Lists Results: " +JSON.stringify(results));
Object.keys(results).forEach((key: string, i: number) => {
console.log("Key: " +results[key]);
let res = results[key][0]; //tried results[key][0]["value"] and results[key]["value"] - both gave undefined
//let listID = res.id;
console.log("Site Lists Results - List ID: " +JSON.stringify(res));
});
Console.log Results:
------------------------------------------------------------------------------------------------
Key: @odata.context https://graph.microsoft.com/v1.0/$metadata#drives(id,name)
Site Lists Results - List ID: "h"
Key: value (2) [{…}, {…}]0: id: "b!pHlD_lSxbkCozGQrFbrTmcaLJVe3f09MnccP5vDr3Q5y_50YoNRJSqWRyeKBbOqh"name: "Documents"__proto__: Object1: id: "b!pHlD_lSxbkCozGQrFbrTmcaLJVe3f09MnccP5vDr3Q4wPyFW_1gbSYPGhq8-0_6b"name: "SPFx Image Rotator"__proto__: Objectlength: 2__proto__: Array(0)
Site Lists Results - List ID: {"id":"b!pHlD_lSxbkCozGQrFbrTmcaLJVe3f09MnccP5vDr3Q5y_50YoNRJSqWRyeKBbOqh","name":"Documents"}
Please help and thanks in advance.
解决方案
推荐阅读
- xamarin - 你知道如何总是在 ContentPage 上显示键盘吗
- google-apps-script - 如何将谷歌表格中的一行数据复制到同一张表格中的另一个选项卡?
- php - 如何测试以匿名函数作为参数执行方法的类方法?
- python - 如何将所有文件普遍存储在内存(变量)Python中
- c# - MSMQ:由于未知原因,消息发送/到达时间差异偶尔会很高
- azure - 在 Azure Kubernetes 服务中为 Promtheus 数据库使用 Azure 存储帐户
- excel - VBA中计数函数的替代方法
- visual-studio-code - 如何在vscode中导入mjs?
- javascript - 使用 React Hooks 时应该如何调度操作?
- python - 如何在显示列名的熊猫中设置合并多级列