[英]React-Native: Accessing JSON
Currently I want to use the JSON data I fetched. 目前,我想使用我获取的JSON数据。 My data looks like this:
我的数据如下所示:
{
"0": {
"date": "2018-12-06T20:49:02.489000",
"encoded": "B64Encoded",
"height": "390",
"name": "image2.jpg",
"width": "390"
},
"1": {
"date": "2018-12-06T20:49:02.489000",
"encoded": "B64Encoded",
"height": "136",
"name": "index.jpg",
"width": "371"
}
}
My problem lays in accessing the JSON Data. 我的问题在于访问JSON数据。 All then time, when I try
所有的时间,当我尝试
fetch('http://127.0.0.1:8888')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
jsonData: responseJson[0].name
})
});
I end up with an undefined object. 我最终得到一个未定义的对象。 I believe the problem is in how the JSON is defined.
我相信问题在于JSON的定义方式。 How can I access it correctly?
如何正确访问它?
fetch('http://127.0.0.1:8888')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
jsonData: responseJson['0'].name
})
});
notice the quotes '0' around the 0 注意0周围的引号'0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.