Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

xmlhttprequest - Is there a way to clean a JSON response that includes unescaped double quotes for a key's value?


Problem:

For a certain request, I occasionally receive a dirty raw JSON response like the following:

{
  "imdbtitle":"Quantum of Solace",
  "type":"movie",
  ...
  "plot": "Is there solace in revenge? Bond and "M" sniff a shadowy international network of 
    power and corruption reaping billions. As Bond pursues the agents of an assassination 
    attempt on "M," all roads lead to Dominic Greene, a world-renowned developer of green 
    technology. Greene, a nasty piece of work, is intent on securing a barren area of Bolivia in 
    exchange for assisting a strongman stage a coup there. The CIA looks the other way, and only 
    Bond, with help from a retired spy and from a mysterious beauty, stands in Greene's way. 
    "M" wonders if she can trust Bond, or if vengeance possesses him. Beyond that, can anyone 
    drawn to Bond live to tell the tale?"
}

Notice the unescaped "M" strewn about in multiple places in the value for the key plot.


More Info:

  • I am not in control of the response received (using a Rapid API service), so I cannot clean this data manually in the DB.

  • I am using Node Fetch and the error was thrown by their built in .json() parser function.

  • I am able to manually access the raw response from the server to parse manually, but am not quite sure what the best approach would be to sanitize in a way accounts for all unescaped double quotes that are sure to be tossed at me in other future responses from this API.


Any help is greatly appreciated :)

question from:https://stackoverflow.com/questions/65648218/is-there-a-way-to-clean-a-json-response-that-includes-unescaped-double-quotes-fo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...