0

Sorry for my english. My question:

Using jsoup i get json response from site. Some entities have unescaped html charactes, for example

{
   "status":200,
   "result":[
      {
         "id":22,        
         "title":"<p>Мир "Юрского периода" искусств</p>",
         "view":1153039,
         "image":{
            "desktop":{
               "image":"img.png",
               "svg":"img.svg"
            }
         },

         "part":{
            "topic":" Глава\Глава"
         }
      }

   ],
   "message":""
}

I use Gson. If i try to deserialize this string i will get error on double quotes in title and "\" in topic. How Can i escape these characters. I only know one way to do this: using regex get string in topic and title and change " to \". The only problem is that there are many such json entity, and it takes a lot of time. Is there a better way?

hardor
  • 3
  • 3
  • 4
    inform the service provider they are not serializing their json correctly. – mavriksc Jun 20 '18 at 21:39
  • @mavriksc It's not my provider, i am parsing someone else's site – hardor Jun 21 '18 at 09:19
  • i don't mean your ISP. it seems like you're hitting an api. who ever is the owner of the site you're making this request to. the json they are sending is bad. let them know about it. what if you go thru all the work to "handle" this issue and then they fix it on their end your solution may not work. best to just have them do it. – mavriksc Jun 21 '18 at 15:02
  • possible solution it's python though https://stackoverflow.com/questions/18514910/how-do-i-automatically-fix-an-invalid-json-string – mavriksc Jun 21 '18 at 15:03

0 Answers0