开发者

What would be the ideal JSON format for this specific XML

开发者 https://www.devze.com 2023-03-17 04:22 出处:网络
Given the following XML example: <Meters> <Meter> <Meter_ID>213</Meter_ID> <Reading1>74.00000</Reading1>

Given the following XML example:

<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>

What would be the most compact JSON format, given that开发者_JAVA百科 the end result is - for each Meter_ID - to get the 3 ReadingN and DateTimeN pairs?


With an array of varying number of reading/datetime pairs per Meter object:

[
    {
        "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"}
        ]
    }
]

With the number of reading/datetime pairs fixed at 3 per Meter object:

[
    {
        "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"
    }
]

Removing the element field names, and just including the key/value pairs of data...

Even more compact form of with an array of varying number of reading/datetime pairs per Meter object:

[
    {
        "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"}
        ]
    }
]

Even more compact form of with the number of reading/datetime pairs fixed at 3 per Meter object:

[
    {
        "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"
    }
]
0

精彩评论

暂无评论...
验证码 换一张
取 消