gpt4 book ai didi

json - Azure 表存储 JSON 返回每个条目的数组而不是单个数组

转载 作者:行者123 更新时间:2023-12-02 08:01:00 25 4
gpt4 key购买 nike

我需要解析 Azure 表存储的 JSON 输出。我能够检索数据,但重新调整的 JSON 似乎为每个数据条目提供一个数组,而不是预期的单个数组。注意:真正的数组应该有 [] 围绕它,所以我不确定如何输出/显示这些数据,因为我似乎无法达到嵌套的值。

我调用表来获取结果如下:

var options = { payloadFormat: "application/json;odata=nometadata" };
tableService.queryEntities('myTable', tableQuery, null, options, function(error, result, response) {
if(!error) {
console.log(response.body.value);
}

例如。我希望每个 https://blogs.msdn.microsoft.com/windowsazurestorage/2013/12/05/windows-azure-tables-introducing-json/ 都能做到这一点:

"value":[
{
"PartitionKey":"Jonathan",
"RowKey":"Foster",
"Timestamp":"2013-12-03T06:45:00.7254269Z",
"Address":"1234 SomeStreet St, Bellevue, WA 75001",
"Email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dc96b3b2bda8b4bdb29cbab3a9aea8b4bfb3babab9b9f2bfb3b1" rel="noreferrer noopener nofollow">[email protected]</a>",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2005-01-05T00:00:00Z",
"Rating":3
},
{
"PartitionKey":"Lisa",
"RowKey":"Miller",
"Timestamp":"2013-12-03T06:45:00.8834427Z",
"Address":"4567 NiceStreet St, Seattle, WA 54332",
"Email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96daffe5f7d6f8f9e4e2fee1fff8f2e2e4f7f2f3e4e5b8f5f9fb" rel="noreferrer noopener nofollow">[email protected]</a>",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2003-01-05T00:00:00Z",
"Rating":2
},
{
"PartitionKey":"Walter",
"RowKey":"Harp",
"Timestamp":"2013-12-03T06:45:00.5384082Z",
"Address":"1345 Fictitious St, St Buffalo, NY 98052",
"Email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c1b2d2038293e0c2f232238233f23622f2321" rel="noreferrer noopener nofollow">[email protected]</a>",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2010-01-05T00:00:00Z",
"Rating":4
}
]
}

但是我得到了这个:

{value: Array(8)}
value: Array(8)
0: {PartitionKey: "Client1", RowKey: "1", Timestamp: "2019-06-05T14:07:08.5541163Z", Location: "eastus", OSType: "WindowsServer", …}
1: {PartitionKey: "Client1", RowKey: "2", Timestamp: "2019-06-04T21:23:42.1804373Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
2: {PartitionKey: "Client1", RowKey: "3", Timestamp: "2019-06-04T21:23:42.2394792Z", PowerState: "VM deallocated", OSType: "SQL2016SP1-WS2016", …}
3: {PartitionKey: "Client1", RowKey: "4", Timestamp: "2019-06-04T21:23:42.2104586Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
4: {PartitionKey: "Client1", RowKey: "5", Timestamp: "2019-06-04T21:23:42.2674991Z", PowerState: "VM running", OSType: "WindowsServer", …}
5: {PartitionKey: "Client1", RowKey: "6", Timestamp: "2019-06-04T21:23:42.3045253Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
6: {PartitionKey: "Client1", RowKey: "7", Timestamp: "2019-06-04T21:23:42.3325452Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
7: {PartitionKey: "Client1", RowKey: "8", Timestamp: "2019-06-04T21:23:42.3665693Z", PowerState: "VM deallocated", OSType: "SQL2017-WS2016", …}
length: 8
__proto__: Array(0)
__proto__: Object

最佳答案

您要求原始 json 字符串,但该库调用为您提供已解析的 json 对象。如果您想要字符串,只需在对象上调用 JSON.stringify() 即可:

var str = JSON.stringify(response.body.value);

TableService.queryEntities 的来源位于 https://github.com/Azure/azure-storage-node/blob/1e315487b8801b8357b8974c7d925313cb143483/lib/services/table/tableservice.js#L811

关于json - Azure 表存储 JSON 返回每个条目的数组而不是单个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56603755/

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