我需要将嵌套的 json(来自 api 的数据)解析为普通的 json(用于创建反应表和可视化),如下所示:
嵌套 json :
{ "count":28,
"value":[ {
"id":"dbff7b54",
"name":"cleansed",
"description":"for business",
"url":"https://www.google.com",
"state":"wellFormed",
"revision":745,
"visibility":"private",
"lastUpdateTime":"2021-02-23T08:57:34.26Z" },
{
"id":"7051f961",
"name":"pub",
"description":"for testing",
"url":"https://wikipedia.com",
"state":"wellFormed",
"revision":9690,
"visibility":"private",
"lastUpdateTime":"2020-08-21T13:06:13.97Z"
} ] }
到这个 json :
"value":
{
"id":"dbff7b54",
"name":"cleansed",
"description":"for business",
"url":"https://www.google.com",
"state":"wellFormed",
"revision":745,
"visibility":"private",
"lastUpdateTime":"2021-02-23T08:57:34.26Z"
},
{
"id":"7051f961",
"name":"pub",
"description":"for testing",
"url":"https://wikipedia.com",
"state":"wellFormed",
"revision":9690,
"visibility":"private",
"lastUpdateTime":"2020-08-21T13:06:13.97Z"
}
这是我的反应代码:
import axios from "axios";
import React,{useEffect,useState} from "react";
const App = () => {
const[data,setData] = useState()
let api = "myapi";
let token = "mytoken";
useEffect(() => {
axios.get(api, { headers: {"Authorization" : `Basic ${token}`} })
.then(res => {
console.log(res)
setData(res.data)
})
.catch(err =>{
console.log(err)
})
},[]);
return(
<div>
</div>
)
}
export default App;
有人可以帮我解析json数据吗?提前致谢。