How to replace only single backslash in java json string -


i getting data wcf webservice :

"[{\"id\":51,\"text\":\"!! sample project !!\"}]"  

i recieving data in android app , using these function remove backslash , start-end double quote , working fine me:

   line = reader.readline();                 string jsonformattedstring = line.replaceall("\\\\", "");//remove backslashes                 jsonformattedstring= jsonformattedstring.substring(1, jsonformattedstring.length()-1) ;//remove start , end double quotes 

now problem getting new data there double quotes within strings , when remove slashes above 2 functions error string ends double quote found , characters after double quotes treated illegal characters. recieving data this:

"[{\"id\":9617,\"text\":\"1 1\/4\\\" pvc\/gi clamps\"}]" 

here if string after 1/4 there double quote(") represents inches when use above function replace backslash error double quote treated end of string.please help.

i using method json data string.

   jsonarray j = new jsonarray(jsonformattedstring);                 jsonobject jsonmain = j.getjsonobject(0);                  int lengthjsonarr = j.length();                  for(int i=0; < lengthjsonarr; i++) {                      jsonmain = j.getjsonobject(i);                     log.d("jsonnnnn----",jsonmain.getstring("text"));                     itm=new citem(jsonmain.getstring("id"),jsonmain.getstring("text"));                     lstitm.add(itm);                   } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -