[英]read file in JSON using fetch
I have a JSON file returned by a server我有一个服务器返回的 JSON 文件
{
"myList": [
{
"film": "A"
},
{
"film": "B"
},
{
"film": "C"
}]
}
And I want to display them with in React native.我想在 React Native 中显示它们。
componentDidMount() {
this.askListing();
}
analyse=(responseJson)=>{
console.log(myList);
}
askListing=()=>{
var getRequest = "https://--------------");
fetch(getRequest)
.then((response) => response.json())
.then((responseJson) => {this.analyse(responseJson)} )
.catch(
(error) => { console.error(error) }
);
}
But in my console I have :但在我的控制台中,我有:
Array [
Object {
"film": "A",
},
Object {
"film": "B",
},
Object {
"film": "C",
},
]
Array and Object are the type of object of class from which it is created. Array 和 Object 是创建它的类的对象类型。
The JavaScript Array object is a global object that is used in the construction of arrays
JavaScript Array 对象是一个全局对象,用于构建数组
The Object constructor creates the key value pairs
Object 构造函数创建键值对
You need to iterate the list in order to access the films您需要迭代列表才能访问电影
for(var i=0; i < myList.length; i++)
console.log(myList[i].film);
myList.film
returns undefined
because film is not a property of the list and moreover an object or a json contains a property that could be accessed using the dot operator. myList.film
返回undefined
因为film不是列表的属性,而且对象或 json 包含可以使用点运算符访问的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.