我在 NodeJS 中有工作代碼。它讀取 json 文件并檢查 json 文件中是否存在電子郵件。const fs = require('fs');let rawdata = fs.readFileSync('users.json');let users = JSON.parse(rawdata);check email if it exists in Json filelet userData = users.find(obj =>{ return obj.email == email})用戶.json[ { "password": "1111", "companyName": "Test2", "username": "test2", "email": "[email protected]" }, { "password": "1111", "companyName": "Test Company", "username": "test", "email": "[email protected]" } ]所以我的問題是如何將 json 文件更改為 API 并讀取它?我在 Contentfull 中有一種“數據庫”,下面的代碼可以獲取信息并在控制臺中顯示let response = client.getEntries({content_type:'user'}) .then(response => console.log(response.items)) .catch(e => { console.log(e); });在 console.log 中顯示這些[ { sys: { space: [Object], id: '1111111', environment: [Object], revision: 2, contentType: [Object], locale: 'en-US' }, fields: { password": '1111', companyName": 'Test Company', username": 'test', email: [email protected] country: 'S', city: 'S', postalCode: '12334', postal: 1111 } }, { sys: { space: [Object], id: '11111wdsd', revision: 2, contentType: [Object], locale: 'en-US' }, fields: { password": '11112', companyName": 'Test2 Company', username": 'test2', email: [email protected] country: 'S', city: 'S', postalCode: '12334', postal: 1111 } }]我怎樣才能訪問和閱讀這個?
讀取 API 而不是 json 文件
慕斯709654
2022-05-14 14:43:01