gpt4 book ai didi

javascript - 如何改进我的 JSON 架构?

转载 作者:行者123 更新时间:2023-12-03 09:29:29 24 4
gpt4 key购买 nike

我这里有这个 JSON:

  [{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ -2.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 1.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, 2.3458776596, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ -5.449212707644754, 2.3458776596, -1.452433 ]
}]

表示图中的点列表。在本例中,给定时间戳有三个点,因此此 JSON 描述了三个图(三个 channel )。

这适用于普通 channel (即简单浮点值列表)。到目前为止一切顺利。

不幸的是,在某些情况下,我们有所谓的“minmax” channel ,其中每个点都表示为一对 float !

让我们以最后一个示例为例,将中间 channel (第二个)替换为“minmax” channel 。这里的问题是我不知道如何对“minmax” channel 的浮点对进行 JSON 化而不产生歧义。

  [{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ -2.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 1.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ 0.449212707644754, ???, 1.452433 ]
},
{
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ -5.449212707644754, ???, -1.452433 ]
}]

最好的方法是什么?我可以在其他数组中包含未命名的数组吗?那么在 Javascript 对象中反序列化这样的 JSON 又如何呢?

最佳答案

您可以在这部分嵌套一个数组,如下所示:

没有极小极大:

  {
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ [0.449212707644754], [1.11111], [1.452433] ]
},

使用极小极大:

  {
"HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68",
"DateTime": "2014-05-13T09:24:49",
"ChannelsValues": [ [0.449212707644754], [1.11111, 1.63245345], [1.452433] ]
},

然后在解析时,您只需检查第二个 channel 有多少个数组元素,这样您就可以确定它是否是极小极大。当然,它的工作原理与 channel 一和 channel 三完全相同。

When typed, an array is represented as open and closed brackets: []which may contain a comma-separated list of values[ "a", "b", "c" ]. These values can be any JSON data type: string, number,boolean, object, array, null. Source: https://www.json.com/json-array

关于javascript - 如何改进我的 JSON 架构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31561553/

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