How Can I Parse Json Which Starts With "/" In Android Using Volley?
I am parsing json data from URl but it starts with '/'. I have a data class which is a POJO class in the app. Here is my json file. /{ 'data': [ { 'id': '
Solution 1:
just remove the "/" from the response by doing:
String subString = (respnse.tostring).replace("/","");
JSONobject jsonObj = newJSONobject(subString);
Gson gson = newGson();
JSONObject data1 = jsonObj.getJSONObject("data");
data = gson.fromJson(data1.toString(), Data.class);
Hope this helps
Solution 2:
If you only want to remove the first slash use this:
if (jsonString.substring(0, 1).equals("/") {
jsonString = jsonString.substring(1);
}
Solution 3:
Before parse the object just remove the "/" from json.
StringjsonString= response.toString();
if (jsonString.contains("/"))
jsonString.replace("/","");
after that parse
Gsongson=newGson();
JSONObjectdata1= jsonString.getJSONObject("data");
data = gson.fromJson(data1.toString(), Data.class);
Hope it will help you!
Post a Comment for "How Can I Parse Json Which Starts With "/" In Android Using Volley?"