我的 API 返回像这样的 JSON 值
[{"UserName":"xxx","Rolename":"yyy"}]
我需要 Username
和 RoleName
值 seperatly 我试过 JSON.parse 但它返回 [Object Object] 请帮助我提前谢谢
最佳答案
考虑以下几点:
var str = '[{"UserName":"xxx","Rolename":"yyy"}]'; // your response in a string
var parsed = JSON.parse(str); // an *array* that contains the user
var user = parsed[0]; // a simple user
console.log(user.UserName); // you'll get xxx
console.log(user.Rolename); // you'll get yyy
关于javascript - JSON.parse 返回 [Object Object] 而不是值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47737093/