-1

I want to parse through JSON, but the problem is, that the json object is located inside a <string> tag. How can I get the JSON object from it?

<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>
Carsten
  • 11,287
  • 7
  • 39
  • 62
Keshri_raj
  • 81
  • 1
  • 8

2 Answers2

0

You may use Regex to get the string or SAX to parse the xml file, and then use new JSONObject(String) to parse JSON

icodesign
  • 876
  • 1
  • 6
  • 12
  • any referral or link or a further xplntn would hlp.. @lee wong...i wnt to get string through SAX parsing... – Keshri_raj May 28 '13 at 06:40
  • try [this link](http://stackoverflow.com/questions/4827344/how-to-parse-xml-using-the-sax-parser/4828765#4828765) – icodesign May 28 '13 at 06:47
  • i hv seen this example bt sorry to say that it didnt hlpd me...bt thnx fr ur hlp....still stucked up with the prblm....... – Keshri_raj May 28 '13 at 10:07
0

Simply read the response into string, then remove the <string> and </string>

Here's a little snippet :

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

You might want to check the response string on LogCat, to do this, add the following code below the above snippet.

Log.d("json", response);

There you can check whether the tags are gone or not, if it is gone, then you can parse the response as JSON.

Good Luck ^^

reidzeibel
  • 1,622
  • 1
  • 19
  • 24