在我的render()方法中,我需要解析嵌套的json对象。请参阅下面的render和json结构部分。 我使用{params.name_last}访问姓氏。 我将如何访问团队下的项目,例如team.name_first
render() {
let { params } = this.props.navigation.state
<Text>{params.name_last}</Text>
}
&#13;
[
{
"id": 1,
"name_first": "Name first 1",
"name_middle": "",
"name_last": "Name last 1",
"name_suffix": "",
"phone": "888-8888",
"fax": "888-8888",
"updated_at": "2015-11-02T21:42:42.000Z",
"team": [
{
"id": 16,
"name_first": "aaa",
"name_middle": "",
"name_last": "bbb",
"name_suffix": ""
},
{
"id": 28,
"name_first": "aaa",
"name_middle": "",
"name_last": "bbb",
"name_suffix": ""
},
{
"id": 29,
"name_first": "aaa ",
"name_middle": "",
"name_last": "bbb",
"name_suffix": ""
}
]
}
]
&#13;
答案 0 :(得分:1)
由于team
是一个数组,您需要访问数组中的特定条目,或者迭代整个数组。
要访问嵌套数组条目中的特定属性(假设您希望对象位于索引i
):
params.team[i].name_first
创建名字数组:
params.team.map(x => x.name_first)