gpt4 book ai didi

java - 格式不正确 - XML 到 Json 的转换

转载 作者:行者123 更新时间:2023-12-01 05:24:33 25 4
gpt4 key购买 nike

<list>
<interfaceReachability type="Critical" count="345" httpLink="searchLradIfAction_pageId?isAscending=true&operation=monitor&searchApByType=AllTypes&searchRadioTypeallRadios=true&searchApType=homePage&severity=1" />
<interfaceReachability type="No Alarms" count="6216" httpLink="searchLradIfAction_pageId?isAscending=true&operation=monitor&searchApByType=AllTypes&searchRadioTypeallRadios=true&searchApType=homePage&severity=5" />
<interfaceReachability type="Minor" count="145" httpLink="searchLradIfAction_pageId?isAscending=true&operation=monitor&searchApByType=AllTypes&searchRadioTypeallRadios=true&searchApType=homePage&severity=3" />
</list>

我想将此 XML 转换为 Json 。由于此 XML 格式不正确且元素包含“&”和“?” Org.json 没有转换 this 。任何帮助将非常感激 。我真的被困在这里。我尝试过

org.json.JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
System.out.println(jsonPrettyPrintString);

但运气不佳。再次感谢

最佳答案

您必须将出现的 '&' 替换为 & 实体,否则它不是有效的 XML。

关于java - 格式不正确 - XML 到 Json 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9867506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com