Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于这个特定的XML,理想的JSON格式是什么_Xml_Json - Fatal编程技术网

对于这个特定的XML,理想的JSON格式是什么

对于这个特定的XML,理想的JSON格式是什么,xml,json,Xml,Json,给出以下XML示例: <Meters> <Meter> <Meter_ID>213</Meter_ID> <Reading1>74.00000</Reading1> <DateTime1>10/05/2011 09:00:18</DateTime1> <Reading2>73.00000</Reading2> <DateTime

给出以下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>

213
74
10/05/2011 09:00:18
73
10/05/2011 09:15:18
70
10/05/2011 09:30:18
69
146
10/05/2011 09:00:18
167
10/05/2011 09:15:18
173
10/05/2011 09:30:18

考虑到最终结果是——对于每个
Meter\u ID
——获得3个
ReadingN
DateTimeN
对,最紧凑的JSON格式是什么?

,每个Meter对象具有不同数量的reading/datetime对数组:

[
    {
        "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"}
        ]
    }
]
[
    {
        "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_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"}
        ]
    }
]
[
    {
        "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"
    }
]
读取/日期时间对的数量固定为每米3个对象:

[
    {
        "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"}
        ]
    }
]
[
    {
        "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_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"}
        ]
    }
]
[
    {
        "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"
    }
]
删除元素字段名,只包括数据的键/值对

更紧凑的形式,每米对象具有不同数量的读取/日期时间对数组:

[
    {
        "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"}
        ]
    }
]
[
    {
        "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_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"}
        ]
    }
]
[
    {
        "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"
    }
]
更紧凑的形式,读取/日期时间对的数量固定为每米3个对象:

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

您希望JSON包含元素名还是仅包含值对?请注意,您发布的XML无效。关闭“仪表”标签无开口。第一个“Meter_ID”标记关闭了两次。只有值对,但我需要确保读取/时间对是连续的(在现实世界中,它们目前以8个为一批)。顺便说一句,匆忙粘贴的XML已更正:-)示例XML仍然无效。每个打开的计量器ID都有两个关闭的对应项。快速更正的XML重新更正…选项3看起来像一个,因为尽管我们现在一次有8个读数,但情况可能并不总是这样。我的三读示例是为了简洁