Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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/0/xml/15.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
使用net.sf.JSON(java)将JSON解析为XML_Java_Xml_Json_Pojo_Jettison - Fatal编程技术网

使用net.sf.JSON(java)将JSON解析为XML

使用net.sf.JSON(java)将JSON解析为XML,java,xml,json,pojo,jettison,Java,Xml,Json,Pojo,Jettison,我正在使用net.sf.JSON将通用JSON解析为XML。(我在转换中未使用POJO Obj) 我正在转换的Json: { "root": { "accountId": "1000", "Items": [ { "cost": 0.1, "debit": 0.1 }, { "cost":

我正在使用net.sf.JSON将通用JSON解析为XML。(我在转换中未使用POJO Obj)

我正在转换的Json:

{
    "root": {
        "accountId": "1000",
        "Items": [
            {
                "cost": 0.1,
                "debit": 0.1
            },
            {
                "cost": 0.2,
                "debit": 0.2
            } 
        ] 
    }
}
在处理我收到的向量时:

<root>
    <entry>
        <accountId>1000</accountId>
        <Items>
            <e>
                <cost>0.1</cost>
                <debit>0.1</debit>
            </e>
            <e>
                <cost>0.2</cost>
                <debit>0.2</debit>
            </e>
        </Items>
    </entry>
</root>

1000
0.1
0.1
0.2
0.2
当我的观点正确时,应该是:

<root>
    <entry>
        <accountId>1000</accountId>
        <Items>
                <cost>0.1</cost>
                <debit>0.1</debit>
        </Items>
        <Items>
                <cost>0.2</cost>
                <debit>0.2</debit>
        </Items>
    </entry>
</root>

1000
0.1
0.1
0.2
0.2
有人使用过这个库并且可以帮助我吗

任何提示都有帮助


提前感谢

将JSON更改为此格式

{ “根”:{ “accountId”:“1000”, “项目”:{“项目”:{“成本”:0.1,“借方”:0.1,“成本”:0.2,“借方”:0.2} }
}

FWIW,我觉得这个结构很好<代码>项目是一个列表;它有条目(
e
)。虽然第二个结构是有效的,但通常最好在列表中包含容器。(如果您不这样做,我会删除元素名称末尾的“s”,因为
Items
现在将表示一个项[单数]。)格式不好的XML:1看起来像库中的bug。你能给我们看一下原始的JSON吗?@Vladmin:accountId是一个输入错误。我在这里更改了一些字段,使其看起来更简单。如果你仍然在寻找解决方案,并且不介意添加另一个库,实用的XML转换器将执行以下操作:--完全公开:我是管理员,也是这个项目的主要贡献者