【发布时间】:2018-06-28 07:34:21
【问题描述】:
我正在尝试列出服务器响应,但我的代码中关于访问嵌套 json 的一些错误..以下是 json 的结构
更新:
{
"child": [],
"courses": [{
"data": {
"name": "Student 1",
"date_created": 1514610451,
"total_students": 4,
"seats": "",
"start_date": false,
"categories": [{
"name": "Subject",
"slug": "Subject"
}],
"intro": {
"id": "1",
"name": "Main Admin",
"sub": ""
},
"menu_order": 0
},
"headers": [],
"status": 200
}]
}
我的反应部分是
render(){
return this.state.course.map(course =>
<Text style={styles.userStyle}>{course.courses.data.map(datas => datas.name)}</Text>
);
}
请帮我找出错误。我得到this.state.course.map不是一个函数。我的获取请求如下
state= {course:[]};
componentWillMount(){
fetch('https://www.mywebsite.com/' + this.props.navigation.state.params.id)
.then((response) => response.json())
.then((responseData) => this.setState({course: responseData}))
}
【问题讨论】:
-
您的 Json 结构无效。验证你的 json 结构:jsonformatter.curiousconcept.com
-
不,我得到了一个有效的 json..
-
你检查过我给出的那个链接吗?因为我得到了无效的json。请通过该链接进行验证
-
是的。我认为你得到了无效的 json,因为我只粘贴了我的 json 响应中的几行。我会更新它。
-
我已经更新了我的问题,现在我得到了一个有效的 json,这是一个错字。但是我怎样才能访问数据?
标签: json react-native jsx