json - 当 json 在 react native 中获取时变得未定义
问题描述
在下面的简化代码中,我能够以 JSON 格式提取数据,但如果我尝试控制台记录对象的特定键,我会得到未定义的。
我原以为我可以this.state.profile.name
用来显示“史蒂文”。undefined
当我能够看到整个响应时,为什么会出现这种情况?谢谢!
state = {
responseJSON: null,
};
callGraph = async token => {
const response = await fetch(
`https://graph.facebook.com/me?access_token=${token}&fields=id,name,email,about,picture`
);
const responseJSON = JSON.stringify(await response.json());
this.setState({
profile: responseJSON
});
console.log("profile = " + this.state.profile);
};
此console.log
输出如下:
profile = {"id":"*******","name":"Steven *******","email":"steve@*******.com","picture":{"data":{"height":50,"is_silhouette":false,"url":"https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=*******&height=50&width=50&ext=1539943832&hash=AeQM2VfUBmdfOVJZ","width":50}}}
解决方案
推荐阅读
- regex - 正则表达式从 Ansible 中的多行捕获文本
- linux - 是否可以在 docker 容器中测试 init.d 脚本
- scala - 如何使用外交将 AHB 端口连接到 DRAM 控制器设备
- django - 在 django 2.2 中的此测试中不允许对“缓存”进行数据库查询
- arrays - swift 符合 Stridable 后进入无限循环
- r - 关于 R 中的数据排序
- node.js - 尝试使用 api 验证 NODE + REACT 时出现错误请求 (400)
- python - 导致文件内容成倍增加的错误
- xamarin.forms - 想要内容页面底部的按钮
- ruby-on-rails-4 - 调试 Resque::Server