关于json-lib的一些问题
或者可以加我QQ:282211932 有验证问题,可以随便填
使用Json-lib-2.3.jar,代码如下
XMLSerializer xmlSerializer = new XMLSerializer();
JSON json = xmlSerializer.read( xml );
System.out.println( json.toString(2) );
用Java把xml转为json时,节点有丢失阿。xml如下:(authors下的author不见了)
<?xml version="1.0" encoding="UTF-8"?>
<important-data certified="true" processed="true">
<timestamp>232423423423</timestamp>
<authors>
<author>
<firstName>Tim</firstName>
<lastName>Leary</lastName>
</author>
</authors>
<title>Flashbacks</title>
<shippingWeight>1.4 pounds</shippingWeight>
<isbn>978-0874778700</isbn>
</important-data>
json如下:
{
"@certified": "true",
"@processed": "true",
"timestamp": "232423423423",
"authors": [ {
"firstName": "Tim",
"lastName": "Leary"
}],
"title": "Flashbacks",
"shippingWeight": "1.4 pounds",
"isbn": "978-0874778700"
}
------解决方案--------------------XML文件改成
XML code
<authors class="object">
...
</authors>
------解决方案--------------------
那就不要用json-lib
FasterXML
https://github.com/FasterXML/jackson-dataformat-xml
or
staxon
https://github.com/beckchr/staxon