【发布时间】:2021-08-24 15:04:48
【问题描述】:
我正在尝试解析 JSON 对象内的 json 字符串,但继续收到“意外令牌”或“意外结束输入”错误。任何帮助将不胜感激!
语法如下:
{
full_name: 'John Doe',
company_name: 'TEST',
sample: 't-e-s-t',
populated: '{"type":"Select","manualTitle":"Manual Title","manualBody":"Email Message will go here","templateTitle":"Title Here","templateBody":"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old."}',
messageBody: 'New body test'
}
【问题讨论】:
-
你用来解析 JSON 的 JS 是什么样的?
-
这是一个 JS 对象,不是 JSON 对象。 (
populated属性是 JSON) -
JSON.parse(obj.populated)
-
@Kinglish OP 将他们的对象字面量称为“JSON 对象”(这是一个没有任何存在权的术语)。但是,是的,它工作正常:jsfiddle.net/2mqxr0kn
标签: javascript json parsing