【问题标题】:get json string within the xml在xml中获取json字符串
【发布时间】:2013-04-24 15:49:06
【问题描述】:

我对 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");

【问题讨论】:

  • 最好要求纯json
  • 你在吗,你真的需要回答吗..
  • 是的...仍在寻找答案:(
  • 检查我的答案,可能对你有帮助

标签: android parsing xml-parsing


【解决方案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,决定你想要什么。

但最好的将是获得纯 json 响应

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    相关资源
    最近更新 更多