【发布时间】:2019-01-09 05:56:04
【问题描述】:
无论如何从 json 数组中获取对象中的值。我需要从一个基于另一个值的对象中获取一个值。
我的代码如下:
export default class StandardComp extends Component {
constructor(props) {
super(props)
this.state = {
id: '',
email: 'abc@gmail.com',
dataSource: []
};
}
componentDidMount(){
fetch(someURL, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({dataSource: responseJson})
//dunno what to do here
})
.catch((error) => {
console.error(error);
})
}
}
我的“responseJson”是这样的。然后提供键值(abc@gmail.com),我怎样才能得到字符串“abcdef”?
[
{
"id": "qwerty",
"email": "cat@gmail.com",
"name": "cat"
},
{
"id": "abcdef",
"email": "abc@gmail.com",
"name": "abc"
}
{
"id": "owowao",
"email": "dog@gmail.com",
"name": "dog"
},
]
提前谢谢你。
【问题讨论】:
标签: json react-native