JSON.parse 返回 [Object Object] 而不是值

2024-04-12

我的 API 返回 JSON 值,例如

[{"UserName":"xxx","Rolename":"yyy"}]

I need Username and RoleNamevalue 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JSON.parse 返回 [Object Object] 而不是值 的相关文章

随机推荐