【发布时间】:2019-09-10 19:47:18
【问题描述】:
我已经为此工作了很长一段时间,但我只是不明白为什么我的 JSON 无效......
JSONLint 显示此错误
Error: Parse error on line 107:
...pair?", "answer": "Yes, as long as the
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
这是 JSON 的片段
{
"tags": "already transferred",
"question": "Can we transfer customers who have already been transferred previously? what is the dispo? warm transfer or already contacted?",
"answer": "Yes, mark as already contacted."
},
{
"tags": "secured debt",
"question": "If customer only has secured debts, can we still offer credit repair?",
"answer": "Yes, as long as they have at least $100 in secured/unsecured debt.
"},
{
"tags": "state",
"question": "Is the program state sensitive?",
"answer": "Yes, each partner has particular states that they service. The script engine will only offer services when the state is valid for partner who has that service."
},
它在说“是的,只要”的地方就失败了
JSON 是在 ColdFusion 中动态创建的。
<cfscript>faqCounter=1;</cfscript>
<CFLOOP query="getFAQs">
<cfoutput>
{"tags":"#getFAQs.tags#","question":"#getFAQs.question#","answer":"#getFAQs.answer#"}<cfif faqCounter<getFAQCount.getFAQPertinentCount>,</cfif>
</cfoutput>
<cfscript>faqCounter++;</cfscript>
</CFLOOP>
【问题讨论】:
-
JSON 字符串中不能有文字换行符,它应该是转义序列
\n。 -
@olegA \n 换行符就在此处的结束报价之前:有担保/无担保债务。"
-
不要尝试通过分别填写每个属性来创建 JSON。对整个数组使用
SerializeJSON()函数。 -
如果任何变量中包含双引号,您的代码也会失败,因为它们不会被转义。
-
不要尝试在数据库中修补它。你的整个方法都是错误的。照我上面说的去做。
标签: javascript json coldfusion lucee