0

我正在使用jQuery 插件将 XML 内容转换为 JSON,但我发现 JSON 内容的排序不正确:

XML:

<list>
    <row>
        <item>interest</item>
        <item>7</item>
        <item>10</item>
        <item>13</item>
        <item>15</item>
        <item>20</item>
        <item>25</item>
        <item>30</item>
    </row>
    <row>
        <item>1.000</item>
        <item>$8,631.87</item>
        <item>$6,132.29</item>
        <item>$4,787.03</item>
        <item>$4,189.46</item>
        <item>$3,219.26</item>
        <item>$2,638.11</item>
        <item>$2,251.48</item>
    </row>
    <row>
        <item>1.630</item>
        <item>$8,823.44</item>
        <item>$6,325.61</item>
        <item>$4,982.41</item>
        <item>$4,386.29</item>
        <item>$3,419.83</item>
        <item>$2,842.51</item>
        <item>$2,459.75</item>
    </row>
    <row>
        <itemb>2.150</itemb>
        <item>$8,983.59</item>
        <item>$6,488.07</item>
        <item>$5,147.43</item>
        <item>$4,553.07</item>
        <item>$3,591.13</item>
        <itemhl>$3,018.36</itemhl>
        <item>$2,640.16</item>
    </row>
</list>

转换后的 JSON 对象:

{
  "list": {
    "row": [
      {
        "item": [
          "interest",
          "7",
          "10",
          "13",
          "15",
          "20",
          "25",
          "30"
        ]
      },
      {
        "item": [
          "1.000",
          "$8,631.87",
          "$6,132.29",
          "$4,787.03",
          "$4,189.46",
          "$3,219.26",
          "$2,638.11",
          "$2,251.48"
        ]
      },
      {
        "item": [
          "1.630",
          "$8,823.44",
          "$6,325.61",
          "$4,982.41",
          "$4,386.29",
          "$3,419.83",
          "$2,842.51",
          "$2,459.75"
        ]
      },
      {
        "itemb": "2.150",
        "item": [
          "$8,983.59",
          "$6,488.07",
          "$5,147.43",
          "$4,553.07",
          "$3,591.13",
          "$2,640.16"
        ],
        "itemhl": "$3,018.36"
      }
    ]
  }
}

根据 XML 是itemb, item, item, item, item, item, itemhl, item, 但 JSON 是itemb, item, item, item, item, item, item, itemhl. 有人可以建议如何解决它,谢谢。

4

1 回答 1

0

JSON 中不能有 2 个具有相同键的键值对。

我相信您想要的是以下内容,但据我所知,这在技术上是不可能的。

{
    "itemb": "2.150",
    "item": [
      "$8,983.59",
      "$6,488.07",
      "$5,147.43",
      "$4,553.07",
      "$3,591.13"
    ],
    "itemhl": "$3,018.36",
    "item": "$2,640.16"
  }
于 2013-02-27T15:37:24.667 回答