[英]Node.js returning an error on a colon in JSON array
我正在嘗試使用 node.js 在服務器端讀取 JSON 文件並使用 fs 讀取它。 當我嘗試解析 JSON 文件時,它適用於單個 object,但是在讀取數組時,它會在冒號上出現錯誤。 The server script is in the same directory as the JSON file, and I wrote my JSON file to comply with the directions shown at https://www.json.org/json-en.html .
我正在嘗試運行的 Javascript 代碼:
console.log('recived login request');
var obj = fs.readFileSync('userInfo.json');
console.log(JSON.parse(obj));
Json文件代碼:
{ "test": [ "testUno" :"yes" ] }
(注:顯示的 json 文件代碼只是一個測試)
好的,事實證明我不知道如何寫 json 但現在我知道了。 哎呀
還建議考慮代碼兼容性,請始終使用字典 { } 作為 json object 的根。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.