我想解析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>
答案 0 :(得分:0)
您可以使用Regex
获取字符串或SAX
来解析xml文件,然后使用new JSONObject(String)
来解析JSON
答案 1 :(得分:0)
只需将响应读入字符串,然后移除<string>
和</string>
这里有一个小片段:
String response = response_from_URL
response = response.replaceAll("<string>", "");
response = response.replaceAll("</string>", "");
您可能需要检查LogCat上的response
字符串,为此,请在上面的代码段下面添加以下代码。
Log.d("json", response);
在那里你可以检查标签是否已经消失,如果它已经消失,那么你可以将response
解析为JSON。
祝你好运^^