【发布时间】:2011-09-19 14:10:02
【问题描述】:
我正在使用 json-lib 库中的 XMLSerializer,以便在 JSON 和 XML 之间来回转换。
有没有办法避免生成<e> 和<a> 节点?这很不方便被路径表达式破坏?
考虑下面的例子:
{"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}}
被序列化为:
<?xml version="1.0" encoding="UTF-8"?>
<o>
<store class="object">
<bicycle class="object">
<color type="string">red</color>
<price type="number">19.95</price>
</bicycle>
<book class="array">
<e class="object">
<author type="string">Nigel Rees</author>
<category type="string">reference</category>
<price type="number">8.95</price>
<title type="string">Sayings of the Century</title>
</e>
<e class="object">
<author type="string">Evelyn Waugh</author>
<category type="string">fiction</category>
<price type="number">12.99</price>
<title type="string">Sword of Honour</title>
</e>
<e class="object">
<author type="string">Herman Melville</author>
<category type="string">fiction</category>
<isbn type="string">0-553-21311-3</isbn>
<price type="number">8.99</price>
<title type="string">Moby Dick</title>
</e>
<e class="object">
<author type="string">J. R. R. Tolkien</author>
<category type="string">fiction</category>
<isbn type="string">0-395-19395-8</isbn>
<price type="number">22.99</price>
<title type="string">The Lord of the Rings</title>
</e>
</book>
</store>
</o>
http://jsontoxml.utilities-online.info/ 提供的东西正是我所追求的,但似乎在 Java 中不可用。
【问题讨论】: