【发布时间】:2016-10-03 10:19:14
【问题描述】:
我已经设法从 API 输出 JSON,但是它是在一个大块中输出的,但是我希望每次有一个关闭的 '}' 时都在一个新行上显示每一块 json。
import React, { Component } from 'react';
import './App.css';
import $ from 'jquery';
class App extends Component {
state = {result : null}
componentDidMount = () => {
$.ajax({
type: "GET",
url: 'http://localhost:3001/data',
data: {},
xhrFields: {
withCredentials: false
},
crossDomain: true,
dataType: 'JSON',
success: (result) => {
this.setState({result : result});
}
});
};
render() {
return (
<div className="App">
<header>
<h2>Last Application Deployment </h2>
</header>
<div id='renderhere'>
{JSON.stringify(this.state.result)}
</div>
</div>
);
}
}
export default App;
【问题讨论】: