当我尝试解析这个JSON字符串时,出现了“Bad control character in string literal in JSON at position 197”错误。
var obj = JSON.parse('[{"name":"Charles freed from Nepal jail","content":"A French serial killer known as The Serpent, convicted of several tourist murders in Asia in the 1970s, has been released from a Nepalese prison.\r\n\r\nCharles Sobhraj, 78, was freed after a court ruled in favour of his age and good behaviour.\r\n\r\nHe spent 19 years in jail in Nepal for killing two North Americans in 1975.","id":"1"}]');
我真的不知道我做错了什么。
我确定,如果我尝试解析没有换行符的json,它可以正常工作,但是当我尝试使用带有换行符的内容时,它就无法工作。 我不确定问题出在哪里。
JSON.parse()
部分即可。如果这只是为了说明问题而进行的简化,那么它可能过于简化了,因为在许多语言中\r\n
是转义序列。 - Álvaro González