使用axios访问服务端API时,发现有时返回的是JSON对象,有时返回的是String,当返回String时,需要在客户端调用JSON.parse。不知道什么原因导致这个问题,在stackoverflow中有这样的回答:
There must be some characters in your response that are escaped in your server side code which are not valid in browser. All server side language have options when converting objects to JSON strings. you can check the invalid response in a JSON linter like https://jsonlint.com/ to see which part causes the problem then search for options to disable this behaviour in your server side code.
应该是服务端返回了无法转换的字符。
网友评论