繁体   English   中英

JSON语法错误-JSON.parse

[英]JSON syntax error - JSON.parse

我在尝试解析此代码时遇到错误(如果不正确,请为格式道歉-我是新来的):

 {
     "message": "Please press 1 or 2 to choose the item from your order",
     "totalPrice":  ${order_res.total_price}, //num
     "OrderNum": ${order_res.order_number}, //num
     "orderID": ${order_res.order_id}, //num
     "customerName": ${order_res.customer_name}, //string
     "itemId": [${id}],
     "itemName": [${items}],
     "itemPrice": [${price}]                      
 }

错误消息:未捕获的语法错误:JSON中位置272处的意外令牌d

我正在发送此JSON作为响应,现在在我添加了最后三个项目之前,在后端接收到此响应时,正在解析该响应,但是由于它们的格式相同,因此我不确定其错误原因,有人可以帮助我吗他们更有经验的眼睛?

谢谢!

修复此行:

"customerName": "${order_res.customer_name}", //string

在您的代码中,如果order_res.customer_name等于“ konichiwa”,那么您将获得:

"customerName": konichiwa

但是您需要:

"customerName": "konichiwa"

另外,如果您有这样的数组:

"itemName": [${['hello', 'world']}]

你得到:

"itemName": [hello, world]

代替:

"itemName": ["hello", "world"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM