json - Azure 表存储 JSON 返回每个条目的数组而不是单个数组
问题描述
我需要解析来自 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);
}
"value":[
{
"PartitionKey":"Jonathan",
"RowKey":"Foster",
"Timestamp":"2013-12-03T06:45:00.7254269Z",
"Address":"1234 SomeStreet St, Bellevue, WA 75001",
"Email":"Jonathan@fourthcoffee.com",
"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":"Lisa@northwindtraders.com",
"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":"Walter@contoso.com",
"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
推荐阅读
- powerbi - 间歇性错误:Prem 服务器上带有 SSAS 的 DAX 表达式
- python - Celery 任务未运行并卡在 PENDING 中
- javascript - 当我尝试做时,对象解构不起作用
- reactjs - 如何在 React Native 中处理令牌存储
- macos - env var 的 MacOS 导出在 shell 上被转义或误解
- python - 不使用字典动态创建变量
- javascript - 获取键值等于 true 的键名 - reactjs
- reactjs - 如何将完整的模块添加到 React Native 项目?
- xml - 使cardview中的两个项目出现在一行中
- r - 使用 Shiny 中的 id 提取元素的名称