解析JSON响应并在React中呈现它

时间:2016-05-30 03:55:50

标签: html json reactjs

我正在尝试在我的反应组件中显示json响应

class JsonComponents extends React.Component {

  constructor() {
    super();

    this.state = {
      components: []
    };
  }



  _fetchComponents() {
   jQuery.ajax ({
      method: 'GET',
      url: 'https://api.github.com/users/mralexgray/repos',
      success: (components) => {
        this.setState({components})
        console.log("Logging something ", this.state.components);
      }
    });


  }
  componentWillMount() {
    this._fetchComponents();
  }

  render() {

// HOw to parse JSON and render it in a table in JSX?
     return <div><pre>{JSON.stringify(this.state.components, null, 2) }</pre></div>;


  }

}

ReactDOM.render(<JsonComponents  />, 
  document.getElementById('container'));

请问我解析返回的json并仅从响应中呈现一个键吗?

0 个答案:

没有答案