如何将其修复为json文件?

时间:2019-01-07 23:58:51

标签: json formatting

所以我有一个Json文件,但不确定其格式是否正确。在每个“时间戳”上,最多可能发生4个事件(在通道1-4上),如果发生0,则根本不会打印时间戳。我将希望能够从每个时间戳为每个通道调用“活动”,“方位角”和“海拔”值。

 {
    "timeStamp": 1440,
    "unix": 1546907973091,
    "events": [
        { "id": 23, "channel": 1, "activity": 0.998, "azimuth": 66.330, "elevation": 47.769 },
        { "id": 20, "channel": 3, "activity": 0.994, "azimuth": 202.169, "elevation": 6.801 }
    ]
},

 {
    "timeStamp": 1448,
    "unix": 1546907973101,
    "events": [
        { "id": 23, "channel": 1, "activity": 0.000, "azimuth": 66.331, "elevation": 47.769 },
        { "id": 20, "channel": 3, "activity": 1.000, "azimuth": 202.166, "elevation": 6.801 }
    ]
}

如果有人可以快速告诉我需要更改的内容,那就太好了。

2 个答案:

答案 0 :(得分:1)

您应该有一个附加成员events来表示事件。像这样:

"unix": 1546905049755,
"events": [
        { "id": 9, "channel": 1, "activity": 1.000, "azimuth": 227.523, "elevation": 10.411 },
        { "id": 3, "channel": 3, "activity": 0.000, "azimuth": 343.892, "elevation": 27.878 }
    ]

此外,删除文件中某些位置提到的][

最终JSON:

[
    {
        "timeStamp": 1808,
        "unix": 1546905049755,
        "events": [
            { "id": 9, "channel": 1, "activity": 1.000, "azimuth": 227.523, "elevation": 10.411 },
            { "id": 3, "channel": 3, "activity": 0.000, "azimuth": 343.892, "elevation": 27.878 }
        ]
    },

    {
        "timeStamp": 1824,
        "unix": 1546905049769,
        "events": [
            { "id": 9, "channel": 1, "activity": 1.000, "azimuth": 227.527, "elevation": 10.436 },
            { "id": 3, "channel": 3, "activity": 0.000, "azimuth": 343.882, "elevation": 27.899 }
        ]
    },

    {
        "timeStamp": 1832,
        "unix": 1546905049777,
        "events": [
            { "id": 9, "channel": 1, "activity": 1.000, "azimuth": 227.528, "elevation": 10.457 },
            { "id": 3, "channel": 3, "activity": 0.000, "azimuth": 343.877, "elevation": 27.910 }
        ]
    }
]

答案 1 :(得分:1)

您必须解决几个问题:

  1. "unix": 1546905049755 [错过了, "events":
  2. 数组括号损坏

这是最接近您的有效JSON:

[
  {
        "timeStamp": 1808,
        "unix": 1546905049755,
        "events": [{
                "id": 9,
                "channel": 1,
                "activity": 1.000,
                "azimuth": 227.523,
                "elevation": 10.411
            },
            {
                "id": 3,
                "channel": 3,
                "activity": 0.000,
                "azimuth": 343.892,
                "elevation": 27.878
            }
        ]
    },
    {
        "timeStamp": 1824,
        "unix": 1546905049769,
        "events": [{
                "id": 9,
                "channel": 1,
                "activity": 1.000,
                "azimuth": 227.527,
                "elevation": 10.436
            },
            {
                "id": 3,
                "channel": 3,
                "activity": 0.000,
                "azimuth": 343.882,
                "elevation": 27.899
            }
        ]
    },
    {
        "timeStamp": 1832,
        "unix": 1546905049777,
        "events": [{
                "id": 9,
                "channel": 1,
                "activity": 1.000,
                "azimuth": 227.528,
                "elevation": 10.457
            },
            {
                "id": 3,
                "channel": 3,
                "activity": 0.000,
                "azimuth": 343.877,
                "elevation": 27.910
            }
        ]
    }
]    

您可以使用JSON validator来验证任何JSON