嗨,我想知道为什么我不能从这个json对象检索objectId,即使我可以在控制台上打印出stringify。
我可以检索所有其他列没有问题,但不是objectId。它发生在我的back4app解析服务器的所有表。
我需要objectId来更新我的程序中的某些列
下面是我的代码
1)
const parseQuery = new Parse.Query("User");
parseQuery.equalTo("username", "Azha");
let queryResult = await parseQuery
.find()
.then((results) => {
results.forEach((prod) => {
//if i change below to prod.get("objectId") error undefined appear
console.log("Product ID Available : " + prod.get("username"));
});
})
.catch((error) => {
console.log(error);
});
const parseQuery = new Parse.Query("User");
parseQuery.equalTo("username", "Azha");
try {
let todos = await parseQuery.find();
if (todos.length > 0) {
//if i change below to todos[0].get("objectId") error undefined appear
console.log("yes Approval : " + todos[0].get("companyname"));
} else {
console.log("No Approval");
}
console.log("- value is : " + JSON.stringify(todos));
console.log("----------------------");
} catch (error) {
Alert.alert("Error!", error.message);
}
下面是json打印输出
[{"sessionToken"r: d9166aa9d7143463c46725d095b53946","username":"Azha","createdAt":"2021 - 09 - 21 - t15:27:01.088z","updatedAt":"2021 - 10 - 10 - t13:01:27.126z","companyname":"XXX","fullname":"XXX","email":"azha@abc.com.my","emailVerified":真的,"accesslevel":"Maintenence","companydivision":"Maintenence","职务n":"Technician"phonenumber":"999","userteam":"B"useremail":"azha@abc.com.my"ACL":{"*":{"read"真},"IuBGmCtxyu":{"read"真的,"write":真正}},"objectId":"IuBGmCtxyu"}]
是的,我刚刚找到了我的解决方案。
下面使用object1:const parseQuery = new Parse.Query("User");
parseQuery.equalTo("username", "Azha");
try {
let todos = await parseQuery.find();
var object1 = JSON.parse(JSON.stringify(todos));
console.log("2- value is : " + object1[0].objectId);
} catch (error) {
Alert.alert("Error!", error.message);
}