React native React本机获取数组json数据

React native React本机获取数组json数据,react-native,React Native,我正在从Mysql中提取数据以响应本机。如您所见,我捕获的数据的输出在数组中。如何提取阵列数据?使用下面的代码,我可以将数据拉入数组。例如,我想从数组中提取新的_image变量 getBusinessNewsData() { fetch('...').then((response) => response.json()) .then((findresponse)=>{ var newSearch = findresponse.new_image; co

我正在从Mysql中提取数据以响应本机。如您所见,我捕获的数据的输出在数组中。如何提取阵列数据?使用下面的代码,我可以将数据拉入数组。例如,我想从数组中提取新的_image变量

  getBusinessNewsData() {
fetch('...').then((response) => response.json())
    .then((findresponse)=>{
  var newSearch = findresponse.new_image;
        console.log(newSearch)

      this.setState({
        data:newSearch,
      })

    })
如果console.lognewSearch为您提供了上面的数组,并且您希望具有new_image属性,则可以设置如下状态。setState{newImage:newSearch[0]。new_image}

通过这样做,this.state.newImage将是数组中的值。

在响应上,并提取新图像

  getBusinessNewsData() {
fetch('...').then((response) => response.json())
    .then((findresponse)=>{
  var newSearch = findresponse.new_image;
        console.log(newSearch)

      this.setState({
        data:newSearch,
      })

    })

然后可以在组件内部状态中设置结果

但在那里它只发射第一个阵列。我还想提取新闻图片的指定值​​在1.2.3.中,您可以使用React Native提供的FlatList组件。它将数据作为数组,并为数组中的每个条目对象返回一个组件。
const result = findResponse.map((d) => d.new_image);