如何在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="http://tempuri.org when i try to create Json Array. Is there any possible to remove string xmlns="http://tempuri.org/" 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