我從PHP的json_encode返回數據消耗 while($row = mysql_fetch_assoc($results)){ echo json_encode($row);
}使用PHP json_encode如何在JavaScript
現在,當我控制檯登錄我得到 {「用戶名」:「養育」,「運動」:」網球 「 」緯度「: 」19.166901「, 」經度「: 」72.951720「} { 」用戶名「: 」anirudh「, 」體育「: 」橄欖球「, 」緯度「: 」19.218330「, 」經度「:」 72.978088 「}
問題是我如何獲得訪問返回的字段。它作爲一個字符串返回。當我做JSON.parse 我得到一個錯誤
VM1115:1 Uncaught SyntaxError: Unexpected token { in JSON at position 85
at JSON.parse (<anonymous>)
at Object.success (form.js:43)
at j (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at x (jquery.min.js:4)
at XMLHttpRequest.b (jquery.min.js:4)
請指點。
非常感謝 Archit瓦希
將您的JSON粘貼到jsonlint.com並查看它是否有效。如果這只是一個調用,那麼您應該在這兩行之間留出逗號,並且它們應該封裝在[]或{}中。 – mkaatman
您正在輸出單個JSON對象。構建數組然後進行編碼。 – AbraCadaver
不,它不。 as theres no no seperator between them 錯誤:第6行解析錯誤: ... ude「:」72.951720「} {\t」username「:」anir --------------- -------^ 期待'EOF','}',',',']','{' – archito2