簡體   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