在Node.js中创建一个新的JSON对象



对不起,我是新的编程,有人可以帮助这个请。我可以记录配置文件对象,一个包含10个项目的JSON对象,但我不能记录vehQ,它应该只包含3个。我写错了吗?

let profile = await this.getProfileDetails(params)
console.log(profile)
var vehQ = {}
if (profile ) {
vehQ["profileID"] = profile[0].profileID
vehQ["regNumber"] = profile[0].regNumber
vehQ["compatibility"] = profile[0].compatibility
console.log(vehQ)

你可能收到JSON作为字符串,你需要将其解析为JS对象。

const parsedProfile = JSON.parse(profile);

最新更新