android - Replace first and last occurrences of a json string -


i fetching response webservice , trying parse json string.

the response string is,

  [{"tbbid":0,"propertyid":1066637,"builderid":"9250c666-e76c-4206-8b37-343b2bb11a89","buildername":"david weekley homes","notes":"","address":"1 tbb4519","schooldistrict":null,"school":null,"cityid":"fort mill","countyid":"","stateid":"sc","zip":"29708","lat":"35.037240000000000","lng":"-80.979742000000000","price":364990,"propertystatusid":"av","propertystatusdescription":"available","stageid":"tbb","stagedescription":"to-be-built home","typeid":1,"typedescription":"house","subdivisionid":4121,"subdivisionname":"baxter village","floorplannumber":"4519","remarks":"","oldnew":null,"propertyinmylistflag":null,"freepostingflag":"f","propertysubscriptionplan":null,"propertysubscriptionpaymenttype":null,"balanceamount":0,"propertylicenseflag":"n","plannumber":null,"subdivisionfloorplanid":null,"subdivisionfloorplanname":"ridgegate","showdirections":"mon-sat 9:30am-5:30pm; sun 12:30pm-5:30","drivingdirections":"take i-77, exit 85 - fort mill / highway 160. take highway 160 west. proceed past main baxter village entrance. turn left baxter village @ next entrance marked white fence , stone monument front street. take first right onto richards crossing, david weekley model located on left @ 3439 richards crossi","propertyclass":"tbb","remarksid":0,"verifiedbu":"y","subdivisiondescription":null,"contact1name":"traci belk","contact1phone":"800-393-9968","contact1phonealt":"","contact2name":"","contact2phone":"","contact2phonealt":"","email":"homes@dwhomes.com","beds":4,"baths":2,"halfbaths":1,"living":0,"dining":0,"otherrooms":"","stories":2.0,"master":"down","garage":2.0,"squarefeet":2474,"lotsize":"","lotdescription":"david weekley homes traditional collection in baxter village offers floor plans featuring innovative design , unsurpassed quality. charming community combines work, play , living, within village. in baxter village, you’ll enjoy:  parks, playgrounds , sports courts swimming pool , clubhouse community library , 2 community centers full time activities director events baxter town center shopping , dining final phase of baxter village sold out! love baxter village want build more customized home on larger estate lot? can help! learn more our build on lot program.","communitytypeid":11,"communitytypedescription":"standard","lotwidth":0,"lotlength":0,"acres":0,"water":"","sewer":"","dryutilities":"","topography":"","trees":"","virtualtoururl":"","internetoption":"","waterid":0,"sewerid":0,"dryutilitiesid":0,"topographyid":0,"treesid":0,"internetoptionid":0,"waterids":null,"sewerids":null,"dryutilitiesids":null,"topographyids":null,"treesids":null,"internetoptionids":null,"minimumprice":0,"maximumprice":0,"minimumpropertysquarefeet":0,"maximumpropertysquarefeet":0,"minimumbeds":0,"maximumbeds":0,"minimumbaths":0,"maximumbaths":0,"minimumhalfbaths":0,"maximumhalfbaths":0,"minimumstories":0,"maximumstories":0,"minimumgarages":0,"maximumgarages":0,"ismodel":null,"customhomemodelid":0,"brandname":null,"schooldistrictid":0,"schooldistrictname":null,"elementaryschool":null,"middleschool":null,"highschool":null,"schoolcomments":"please visit school district's website additional information attendance boundaries , school activities.","hashoa":true,"hoa":"","hoafee":0,"hoabillingperiod":"","commissionpaid":"tbd","buyerincentive":"please call current incentives.","agentincentive":"please call current incentives.","propertyimageid":5483435,"propertyimage":"propertyimages/20130218\\p1066637__021813220800_817965289_5483435.jpg","ismodified":false,"statusid":40,"statusdescription":"active","entrydate":new date(1350438233950),"modifydate":new date(1361225162697),"availabledate":new date(-59011459200000),"useridmodifiedby":"4a2aef16-e7d9-469a-95ad-5c8935cb6bab","useridapprovedby":"00000000-0000-0000-0000-000000000000","useridcreatedby":"4a2aef16-e7d9-469a-95ad-5c8935cb6bab","propertycountperlogtype":0,"photosource":null,"completiondate":new date(-59011459200000),"qaedflag":null,"projectname":"","siteplansrc":null,"marketingoverview":null,"areadescription":null,"developerandprojectteam":null,"buildingfeatures":null,"otherinformation":null,"hoadocspdf":null,"unitno":null,"imagecount":0,"propertyimagedescription":null,"colorschemecode":null,"colorschemeid":0,"colorschemename":null,"directioncode":null,"directiondescription":null,"viewdescription":null,"builderemail":null,"logosource":null,"condoimagesource":"","floorplancount":0,"masterdescription":null,"colorschemecount":0}] 

but when pasring getting exception

 org.json.jsonexception: unterminated string @ character 1919 

that when parsing line

lotdescription":"david weekley homes traditional collection in baxter village offers floor plans featuring innovative design , unsurpassed quality. charming community combines work, play , living, within village. in baxter village,  

there special character in word

 you’ll  

so, trying replace double quote(") escape double quote(\") , code ,

  public void ......(){   httppost.setentity(new urlencodedformentity(namevaluepairs));   httpresponse response = client.execute(httppost);   string jsonstring=getjsonstring(response);                   jsonarray json = new jsonarray(jsonstring);  }   public string getjsonstring(httpresponse response) {      try {          documentbuilder builder = documentbuilderfactory.newinstance().newdocumentbuilder();          document doc = builder.parse(response.getentity().getcontent());          nodelist nl = doc.getelementsbytagname("string");          node n = nl.item(0);          string str = n.getfirstchild().getnodevalue().replace("\"", "\\\"");           system.out.println("node value : " +  str);          return str;           }catch(exception e){}      } 

i using replace function , replacing string escape quote thinking special characters parsed. doesn't seem work.

i want whole string in format \"string\" or whole string parsed. did trails , did research not find solution.

any ideas or suggestions please!! in advance!!!

the logcat is,

05-21 15:23:37.843: w/system.err(17883): org.json.jsonexception: unterminated string @ character 1919 of [{"tbbid":0,"propertyid":1066637,"builderid":"9250c666-e76c-4206-8b37-343b2bb11a89","buildername":"david weekley homes","notes":"","address":"1 tbb4519","schooldistrict":null,"school":null,"cityid":"fort mill","countyid":"","stateid":"sc","zip":"29708","lat":"35.037240000000000","lng":"-80.979742000000000","price":364990,"propertystatusid":"av","propertystatusdescription":"available","stageid":"tbb","stagedescription":"to-be-built home","typeid":1,"typedescription":"house","subdivisionid":4121,"subdivisionname":"baxter village","floorplannumber":"4519","remarks":"","oldnew":null,"propertyinmylistflag":null,"freepostingflag":"f","propertysubscriptionplan":null,"propertysubscriptionpaymenttype":null,"balanceamount":0,"propertylicenseflag":"n","plannumber":null,"subdivisionfloorplanid":null,"subdivisionfloorplanname":"ridgegate","showdirections":"mon-sat 9:30am-5:30pm; sun 12:30pm-5:30","drivingdirections":"take i-77, exit 85 - fort mill / highway 160. take highway 160 west. proceed past main baxter village entrance. turn left baxter village @ next entrance marked white fence , stone monument front street.  take first right onto richards crossing, david weekley model located on left @ 3439 richards crossi","propertyclass":"tbb","remarksid":0,"verifiedbu":"y","subdivisiondescription":null,"contact1name":"traci belk","contact1phone":"800-393-9968","contact1phonealt":"","contact2name":"","contact2phone":"","contact2phonealt":"","email":"homes@dwhomes.com","beds":4,"baths":2,"halfbaths":1,"living":0,"dining":0,"otherrooms":"","stories":2.0,"master":"down","garage":2.0,"squarefeet":2474,"lotsize":"","lotdescription":"david weekley homes traditional collection in baxter village offers floor plans featuring innovative design , unsurpassed quality. charming community combines work, play , living, within village. in baxter village, 05-21 15:23:37.867: w/system.err(17883):    @ org.json.jsontokener.syntaxerror(jsontokener.java:446) 05-21 15:23:37.867: w/system.err(17883):    @ org.json.jsontokener.nextstring(jsontokener.java:226) 05-21 15:23:37.867: w/system.err(17883):    @ org.json.jsontokener.nextvalue(jsontokener.java:103) 05-21 15:23:37.882: w/system.err(17883):    @ org.json.jsontokener.readobject(jsontokener.java:381) 05-21 15:23:37.890: w/system.err(17883):    @ org.json.jsontokener.nextvalue(jsontokener.java:96) 05-21 15:23:37.898: w/system.err(17883):    @ org.json.jsontokener.readarray(jsontokener.java:426) 05-21 15:23:37.898: w/system.err(17883):    @ org.json.jsontokener.nextvalue(jsontokener.java:99) 05-21 15:23:37.906: w/system.err(17883):    @ org.json.jsonarray.<init>(jsonarray.java:87) 05-21 15:23:37.914: w/system.err(17883):    @ org.json.jsonarray.<init>(jsonarray.java:103) 

and getjsonstring result,

 05-21 15:21:18.382: i/system.out(17883): node value : [{"tbbid":0,"propertyid":1066637,"builderid":"9250c666-e76c-4206-8b37-343b2bb11a89","buildername":"david weekley homes","notes":"","address":"1 tbb4519","schooldistrict":null,"school":null,"cityid":"fort mill","countyid":"","stateid":"sc","zip":"29708","lat":"35.037240000000000","lng":"-80.979742000000000","price":364990,"propertystatusid":"av","propertystatusdescription":"available","stageid":"tbb","stagedescription":"to-be-built home","typeid":1,"typedescription":"house","subdivisionid":4121,"subdivisionname":"baxter village","floorplannumber":"4519","remarks":"","oldnew":null,"propertyinmylistflag":null,"freepostingflag":"f","propertysubscriptionplan":null,"propertysubscriptionpaymenttype":null,"balanceamount":0,"propertylicenseflag":"n","plannumber":null,"subdivisionfloorplanid":null,"subdivisionfloorplanname":"ridgegate","showdirections":"mon-sat 9:30am-5:30pm; sun 12:30pm-5:30","drivingdirections":"take i-77, exit 85 - fort mill / highway 160. take highway 160 west. proceed past main baxter village entrance. turn left baxter village @ next entrance marked white fence , stone monument front street.  take first right onto richards crossing, david weekley model located on left @ 3439 richards crossi","propertyclass":"tbb","remarksid":0,"verifiedbu":"y","subdivisiondescription":null,"contact1name":"traci belk","contact1phone":"800-393-9968","contact1phonealt":"","contact2name":"","contact2phone":"","contact2phonealt":"","email":"homes@dwhomes.com","beds":4,"baths":2,"halfbaths":1,"living":0,"dining":0,"otherrooms":"","stories":2.0,"master":"down","garage":2.0,"squarefeet":2474,"lotsize":"","lotdescription":"david weekley homes traditional collection in baxter village offers floor plans featuring innovative design , unsurpassed quality. charming community combines work, play , living, within village. in baxter village, 

you need replace string before document doc = builder.parse(); because & take illegal character.

so, need replace character before parse call.

      httpentity httpentity = response.getentity();     string xml = entityutils.tostring(httpentity);  inputstream stream = new bytearrayinputstream(             (xml.replace("&", "&amp;"))                     .getbytes("utf-8"));      document doc = builder.parse(stream); 

thanks.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -