给出以下XML示例:
<Meters>
<Meter>
<Meter_ID>213</Meter_ID>
<Reading1>74.00000</Reading1>
<DateTime1>10/05/2011 09:00:18</DateTime1>
<Reading2>73.00000</Reading2>
<DateTime2>10/05/2011 09:15:18</DateTime2>
<Reading3>70.00000</Reading3>
<DateTime3>10/05/2011 09:30:18</DateTime3>
</Meter>
<Meter>
<Meter_ID>69</Meter_ID>
<Reading1>146.00000</Reading1>
<DateTime1>10/05/2011 09:00:18</DateTime1>
<Reading2>167.00000</Reading2>
<DateTime2>10/05/2011 09:15:18</DateTime2>
<Reading3>173.00000</Reading3>
<DateTime3>10/05/2011 09:30:18</DateTime3>
</Meter>
</Meters>
最紧凑的JSON格式是什么,假设最终结果是 - 对于每个Meter_ID
- 获得3 ReadingN
和DateTimeN
对?
答案 0 :(得分:1)
每个Meter对象具有不同数量的读取/日期时间对的数组:
[
{
"Meter_ID": 213,
"Readings":[
{"Reading1": 74,"DateTime1": "10/05/2011 09:00:18"},
{"Reading2": 73,"DateTime2": "10/05/2011 09:15:18"},
{"Reading3": 70,"DateTime3": "10/05/2011 09:30:18"}
]
},
{
"Meter_ID": 69,
"Readings":[
{"Reading1": 146,"DateTime1": "10/05/2011 09:00:18"},
{"Reading2": 167,"DateTime2": "10/05/2011 09:15:18"},
{"Reading3": 173,"DateTime3": "10/05/2011 09:30:18"}
]
}
]
读取/日期时间对的数量固定为每米对象3:
[
{
"Meter_ID": 213,
"Reading1": 74,
"DateTime1": "10/05/2011 09:00:18",
"Reading2": 73,
"DateTime2": "10/05/2011 09:15:18",
"Reading3": 70,
"DateTime3": "10/05/2011 09:30:18"
},
{
"Meter_ID": 69,
"Reading1": 146,
"DateTime1": "10/05/2011 09:00:18",
"Reading2": 167,
"DateTime2": "10/05/2011 09:15:18",
"Reading3": 173,
"DateTime3": "10/05/2011 09:30:18"
}
]
删除元素字段名称,只包括数据的键/值对...
每个Meter对象具有不同数量的读取/日期时间对数组的更紧凑形式:
[
{
"Meter_ID": 213,
"Readings":[
{"74": "10/05/2011 09:00:18"},
{"73": "10/05/2011 09:15:18"},
{"70": "10/05/2011 09:30:18"}
]
},
{
"Meter_ID": 69,
"Readings":[
{"146": "10/05/2011 09:00:18"},
{"167": "10/05/2011 09:15:18"},
{"173": "10/05/2011 09:30:18"}
]
}
]
更紧凑的形式,读数/日期时间对固定为每米3对象:
[
{
"Meter_ID": 213,
"74": "10/05/2011 09:00:18",
"73": "10/05/2011 09:15:18",
"70": "10/05/2011 09:30:18"
},
{
"Meter_ID": 69,
"146": "10/05/2011 09:00:18",
"167": "10/05/2011 09:15:18",
"173": "10/05/2011 09:30:18"
}
]