【发布时间】:2019-05-28 10:23:55
【问题描述】:
我正在尝试将多个 JSON 对象组合到一个 JSON 数组中,并可能过滤数据名称(温度、压力、高度)。
我尝试使用 JSON-Simple 和 Java,但无法使用。
以下是 JSON 的片段:
我要转换的输入:
{"temperature" : -12, "sendtimes" : 10000}
{"pressure" : 1000, "sendtimes" : 10001}
{"altitude" : 100.7, "sendtimes" : 10002}`
转换后我想要它:
{
"temperaturData": [
{"temperature": -12, "sendtimes": 10000},
{"pressure" : 1000, "sendtimes" : 10001},
{"altitude" : 100.7, "sendtimes" : 10002},
]
}
我不知道如何做到这一点,感谢所有可以帮助我的人!
【问题讨论】:
-
感谢您的回复,但在那个问题中,输入已经格式化,我只有一个包含这三个对象的文件
-
两个问题:输入文件是否保持原样,没有被
{}或[]包围?这是{"temperature" : -12, "sendtimes" : 10000}在单行中,而所有其他单独的{}包含在单行中的数据吗?
标签: java json type-conversion