JSON.parse返回[Object Object]而不是值 [英] JSON.parse returning [Object Object] instead of value
本文介绍了JSON.parse返回[Object Object]而不是值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的API返回JSON值,例如
My API returning the JSON value like
[{"UserName":"xxx","Rolename":"yyy"}]
我分别需要Username
和RoleName
值,我尝试过JSON.parse,但返回的[Object Object]请先帮助我
I need Username
and RoleName
value seperatly i tried JSON.parse but its returning [Object Object] Please help me thanks in advance
推荐答案
请考虑以下内容:
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
这篇关于JSON.parse返回[Object Object]而不是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文