You have to determine where the JSON.parse()
method is being invoked and then proceed it with a test for whether the JSON is valid before trying to use the parsed output.(您必须确定在何处调用JSON.parse()
方法,然后在尝试使用解析后的输出之前对其进行测试,以测试JSON是否有效。)
For example:(例如:)
const isValidJson = jsonString => {
try {
JSON.parse(jsonString)
return true
} catch(err) {
return false
}
}
if (isValidJson(jsonString)) JSON.parse(jsonString)
The likeliest culprit for where this parsing is happening appears to be in your game API, since it seems to be handling your app's routes.(进行解析的最可能的罪魁祸首似乎在您的游戏API中,因为它似乎正在处理您应用的路由。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…