[英]Javascript - JSON.parse: unexpected end of data - Error when using valid JSON. What am I doing wrong?
[英]JSON.parse, what am I doing wrong?
所以,我試圖在Javascript中解析一些JSON。 這感覺它應該工作,但我收到一個錯誤。 這是函數調用:
JSON.parse("{player: 'green', direction: 'north'}");
這是錯誤
VM156:1 Uncaught SyntaxError: Unexpected token p in JSON at position 1
at Object.parse (native)
at <anonymous>:1:6
我在一個空的網頁上嘗試這個,沒有JS庫。
該字符串,只是作為Javascript執行創建一個具有兩個預期屬性的對象。
我試過把字符串包裹起來。 那不解析。
意外的令牌似乎是第一個字母。
我做錯了什么,我該如何解析這個對象?
這不是有效的JSON 。
嘗試這個:
JSON.parse('{"player": "green", "direction": "north"}');
請注意雙引號"
而不是單引號'
和對象鍵周圍的引號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.