我想通过JSON解析,但问题是,JSON对象位于<string>
标记内。如何从中获取JSON对象?
<string>
{ "SubListList" : {
"SubList" : [
{
"Description" : null,
"Items" : "6",
"Name" : "ANAESTHETICS",
"PPLID" : "4",
"SubListID" : "87",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "6",
"Name" : "Berris",
"PPLID" : "4",
"SubListID" : "93",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "18",
"Name" : "Dentsply",
"PPLID" : "4",
"SubListID" : "92",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "2",
"Name" : "INFECTION CONTROL",
"PPLID" : "4",
"SubListID" : "88",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "3",
"Name" : "LABORATORY PRODUCTS",
"PPLID" : "4",
"SubListID" : "89",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "1",
"Name" : "SURGICAL SUNDRIES",
"PPLID" : "4",
"SubListID" : "90",
"poSubListItemList" : "clsSubListItemList"
},
{
"Description" : null,
"Items" : "6",
"Name" : "X-RAY PRODUCTS",
"PPLID" : "4",
"SubListID" : "91",
"poSubListItemList" : "clsSubListItemList"
}
] }
}
</string>
只需将响应读入字符串,然后删除<string>
和</string>
下面是一小段代码:
String response = response_from_URL
response = response.replaceAll("<string>", "");
response = response.replaceAll("</string>", "");
您可能想要检查LogCat上的response
字符串,为此,在上面的代码片段下面添加以下代码。
Log.d("json", response);
在那里你可以检查标签是否消失了,如果它消失了,那么你可以将response
解析为JSON。
Good Luck ^^
您可以使用Regex
获取字符串或SAX
来解析xml文件,然后使用new JSONObject(String)
来解析JSON