我正在使用 JSON.parse() 函数在我的论坛中处理问题和答案(存储在某处)。对于像这样的回应
response = {"Q":"What is PHP","reply":"Google it"}
它工作正常,但如果用户输入带有引号的内容,我会遇到问题,例如
response = {"Q":"What is PHP","reply":"Google **"what is php"**"}
我将如何逃避那些引号?
在任何嵌入的双引号前加上反斜杠:
response = {"Q":"What is PHP","reply":"Google \"what is php\""}
来自 javascript 使用encodeUriComponent
来自 php 使用urlencode
逃脱它
response = {"Q":"What is PHP","reply":"Google **\"what is php\"**"}