Получение ответа от веб-службы Asp.net в React native - PullRequest
0 голосов
/ 26 сентября 2019

мы пытаемся получить ответ json веб-сервисов в нашем реагирующем нативе.Мы можем получить после попытки его по-разному.наш ответ Json от веб-сервисов выглядит следующим образом: {

"Таблица": [{"code": "M251", "firstname": "MINAL JAGDISH TRIVEDI"}]}

Код, который мы пишем для ответа в нативном режиме:

import React from 'react';
import { FlatList, ActivityIndicator, Text, View  } from 'react-native';

export default class HomeScreen extends React.Component {

  constructor(props){
    super(props);
    this.state ={ isLoading: true}
  }

  componentDidMount(){
     return fetch('URL',{ 
      method: 'POST',
      headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
      },
   })
      .then((response) => response.json())
      .then((responseJson) => {

        this.setState({
          isLoading: false,
          dataSource: responseJson.Table,

        });

      })
      .catch((error) =>{
        console.error(error);
      });
  }



  render(){

    if(this.state.isLoading){
      return(
        <View style={{flex: 1, padding: 20}}>
          <ActivityIndicator/>
        </View>
      )
    }

    return(
      <View style={{flex: 1, paddingTop:20}}>
        <FlatList
          data={this.state.dataSource}

          renderItem={({item}) => <Text>{item.code}, {item.firstname}</Text>}

          keyExtractor={({id}, index) => id}
        />
      </View>
    );

  }
}

Пожалуйста, предоставьте решение, если кто-то уже сталкивался с этой проблемой.

...