在json字符串中具有数组的json xml转换器 [英] json xml converter having array in json string
本文介绍了在json字符串中具有数组的json xml转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将json转换为xml,稍后再将该json转换回xml,但是在此转换过程中,我失去了json数组对象- 我正在使用org.json lib.
I need to convert a json to xml and later on converting that json back to xml, but i am loosing the json array object while this conversion - I am using org.json lib.
Json String-
Json String -
{
"readResult": {
"errors": [{
"code": 400
}]
}
}
代码库-使用org.json lib
Codebase - using org.json lib
String xml = XML.toString(new JSONObject("inputjsonstring"));
String json = XML.toJSONObject(xml).toString();
输出xml和json-
Output xml and json -
XML - <readResult><errors><code>400</code></errors></readResult>
JSON -
{
"readResult": {
"errors": {
"code": 400
}
}
}
此处此json没有原始json中的任何数组.请建议备用库执行相同的操作.
Here this json doesn't have any array as it was in original json. Please suggest alternate library to do the same.
推荐答案
下划线Java 可以将json转换为xml,反之亦然.我是该项目的维护者.
Underscore-java can convert json to xml and vice versa. I am the maintainer of the project.
结果xml:
<?xml version="1.0" encoding="UTF-8"?>
<readResult>
<errors array="true">
<code number="true">400</code>
</errors>
</readResult>
这篇关于在json字符串中具有数组的json xml转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文