So I'm using the fetch api to get some data. I have sucessfully managed to get the data and can display the response with console log. However, I want to actually use this data. The api gives me "result", "id" and "total". I need help how can I convert this to a string array and actually use the information generated from the api.
I have tried messing around with JSON.Parse but I haven't really been able to convert the json data to a string array.
function addPost(e){ e.preventDefault();
let itemname = document.getElementById('itemname').value;
let body = document.getElementById('body').value;
fetch('https://cors-anywhere.herokuapp.com/https://www.pathofexile.com/api/trade/search/Standard', {
method:'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type':'application/json'
},
body:JSON.stringify({"query": {"status": {"option": "online"}, "name":itemname, "stats": [{"type": "and", "filters": []}]},"sort": {"price": "asc"}})
})
.then((res) => res.json())
.then((data) => console.log(JSON.stringify(data)));
}
I think this is what you are looking for->
var item;
fetch('https://cors-anywhere.herokuapp.com/https://www.pathofexile.com/api/trade/search/Standard', {
method:'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type':'application/json'
},
body:JSON.stringify({"query": {"status": {"option": "online"}, "name":itemname, "stats": [{"type": "and", "filters": []}]},"sort": {"price": "asc"}})
})
.then((res) => res.json())
.then((data) => item = JSON.stringify(data));
JSON.parse(item).result
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.