【发布时间】:2021-04-26 18:29:42
【问题描述】:
我有一个输入字符串
let input = '{"username": "John Doe", "email": "john@example.com"} trailing text'
我想JSON.parse它,但由于尾随文本而失败。
Uncaught SyntaxError: Unexpected token t in JSON at position 54
at JSON.parse (<anonymous>)
at <anonymous>:1:6
如何从该文本中解析 JSON 对象而忽略尾随文本?
【问题讨论】:
-
对尾随文本中可能存在的字符是否有任何限制?
-
@Gershy 没有限制,可以有任何文字。
标签: javascript json jsonparser