我真的很震惊xml解析。我有一个像这样的xmlstring
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://a.com /">{"Id":87,"Name":"jo@a.com","FirstName":"Jo","LastName":"var","Profile":"","Designation":""}</string>
我想把json作为字符串..我不知道该怎么做..
我在下面给出的尝试..我真的很震惊请帮助我
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(fromServer));
Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("data");
答案 0 :(得分:1)
试试这个
我发布这个答案只是为了帮助,但这不是最好的方法。
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://a.com /">
</string>
这些将与您的回复一起出现,因此每次都是相同的。只需用空白空间替换它们
String str=yourjsonresponse;
str=str.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>"," ");
str=str.replace("<string xmlns=\"http://a.com /\">"," ");
str=str.replace("</string>"," ");
看起来很奇怪,但会奏效。
另一种方法是使用jsoup
,决定你想要的东西。
但是Best将获得纯粹的json respose