如何在Android中将Xml字符串转换为Json对象? [英] how to convert Xml String To Json Object in Android?

查看:110
本文介绍了如何在Android中将Xml字符串转换为Json对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<string xmlns="http://tempuri.org/">

    [{"POSCODE":"01","POSDESC":"BAR"},
    {"POSCODE":"13","POSDESC":"CAT AC"},
    {"POSCODE":"02","POSDESC":"CATERING"},
    {"POSCODE":"15","POSDESC":"CLUB FUNCTIONS"},
    {"POSCODE":"07","POSDESC":"GYM"},
    {"POSCODE":"14","POSDESC":"OTHERS"},

</string>





这是我的Asp.net webservice JsonString输出



我的webservice当我尝试创建Json数组时,响应字符串xmlns =& quot; http://tempuri.org。有没有可能删除字符串xmlns =& quot; http://tempuri.org/& quot;来自android ??



预标签位置已修改 - Naz_Firdouse [/ Edit]



This is my Asp.net webservice JsonString Output

my webservice Responce string xmlns=&quot;http://tempuri.org when i try to create Json Array. Is there any possible to remove string xmlns=&quot;http://tempuri.org/&quot; from android??

Pre tags placement modified - Naz_Firdouse[/Edit]

推荐答案

你的字符串结果已经是JSON;)

只需修改字符串的结尾,然后阅读它并根据需要使用它。

Your string result is already in JSON ;)
Just revise the end of your string, then read it and use it as you want.
[{"POSCODE":"01","POSDESC":"BAR"},
{"POSCODE":"13","POSDESC":"CAT AC"},
{"POSCODE":"02","POSDESC":"CATERING"},
{"POSCODE":"15","POSDESC":"CLUB FUNCTIONS"},
{"POSCODE":"07","POSDESC":"GYM"},
{"POSCODE":"14","POSDESC":"OTHERS"}]



如果你的结果是真正的XML格式,我建议给你这个链接;)

http://stackoverflow.com/questions/18337394/convert -xml-to-json-object-in-android [ ^ ]


你已经完成了!如果您只想删除该特定文本部分。你也可以使用这个简单的方法。



You already have it done! If you just want to remove that one particular text part. You can use this simple method too.

// ignore this part.
xmlns="http://tempuri.org/"
// 
String stringContent = "JsonResultAsStringHere";
String newString = stringContent.Replace("xmlns=\"http://tempuri.org/\"", "");
// use it anywhere as newString.





这样就可以了。它只会从String中删除该属性,然后您可以将其转换回XML。



This would do it. It would just remove the attribute from the String and then you can convert it back to the XML.


C#Xml到Json代码。



http://xamarin.me/wordpress/?p=7 [ ^ ]





谢谢,

Harshad
C# Xml to Json code here.

http://xamarin.me/wordpress/?p=7[^]


Thanks,
Harshad


这篇关于如何在Android中将Xml字符串转换为Json对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆