2012-03-26 100 views
1
<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不会转换这个。任何帮助将非常感激 。我真的坚持在这里。我试过格式不正确-XML至Json转换

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

但是没有运气。再次感谢

+0

哪个xml?多一点信息真的会有帮助。 – Thomas 2012-03-26 06:42:04

+0

您是否尝试过使用Xstream?我认为你可以读取xml作为对象,然后使用json writer:http://xstream.codehaus.org/json-tutorial.html。示例xml肯定会有所帮助。 – 2012-03-26 06:49:08

+0

@Thomas我现在添加了xml @Petro,如果你不介意,你可以添加代码。我也尝试过Xstream,但是我无法使用.BX标记的名称将动态更改。谢谢你的帮助 – eagerToLearn 2012-03-26 07:13:55

回答

0

您将不得不用&amp;实体替换出现'&',否则它不是有效的XML。