-1

我想通过 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>
4

2 回答 2

0

您可以使用Regex获取字符串或SAX解析 xml 文件,然后使用new JSONObject(String)解析 JSON

于 2013-05-28T06:29:39.743 回答
0

只需将响应读入字符串,然后删除<string></string>

这是一个小片段:

String response = response_from_URL
response = response.replaceAll("<string>", "");
response = response.replaceAll("</string>", "");

您可能想要检查responseLogCat 上的字符串,为此,请在上述代码段下方添加以下代码。

Log.d("json", response);

在那里您可以检查标签是否消失,如果消失,则可以将其解析response为 JSON。

祝你好运^^

于 2013-05-28T07:35:32.087 回答