关于从 JSON 流中提取数据的建议

发布于 2025-01-11 09:28:55 字数 837 浏览 0 评论 0原文

我有一个 JSON 数据流,其中包含一堆以“Data:”标签为前缀的 JSON 对象。制作此有效 JSON 以便我可以在应用程序中利用数据流的最简单方法是什么?给出的 URL 会不断更新,因此没有尽头。

一些流数据的简短片段:

data: {"value":12,"id":"window_doneTodayCount_1","updatedAt":1646316313574}

data: {"value":"4:30","id":"window_averageTime_1","updatedAt":1646316313596}

data: {"value":"Tue 11:05","id":"window_lastUpdatedTime","updatedAt":1646316313746}

我希望将其动态转换为如下所示的内容,这将是有效的,我可以在应用程序中使用:

[{
        "value": 12,
        "id": "window_doneTodayCount_1",
        "updatedAt": 1646316313574
    },
    {
        "value": "4:30",
        "id": "window_averageTime_1",
        "updatedAt": 1646316313596
    }, {
        "value": "Tue 11:05",
        "id": "window_lastUpdatedTime",
        "updatedAt": 1646316313746
    }
]

甚至不确定这是否可能,因为我从未见过这样的文件。

谢谢。

I have a JSON data stream which contains a bunch of JSON objects prefixed with the 'Data: ' label. What is the simplest way to make this valid JSON so I can utilise the data stream in an application? The URL given is constantly updating so it has no end.

Short snippet of some of the streamed data:

data: {"value":12,"id":"window_doneTodayCount_1","updatedAt":1646316313574}

data: {"value":"4:30","id":"window_averageTime_1","updatedAt":1646316313596}

data: {"value":"Tue 11:05","id":"window_lastUpdatedTime","updatedAt":1646316313746}

I am looking to convert this dynamically to something like the below, which would be valid and I can use within an app:

[{
        "value": 12,
        "id": "window_doneTodayCount_1",
        "updatedAt": 1646316313574
    },
    {
        "value": "4:30",
        "id": "window_averageTime_1",
        "updatedAt": 1646316313596
    }, {
        "value": "Tue 11:05",
        "id": "window_lastUpdatedTime",
        "updatedAt": 1646316313746
    }
]

Not even sure if this is possible as I have never seen a file like this.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文