How do I retrieve the 'name' and 'description' from the JSON data below? I have tried in my code (see below) but couldn't figure it out. Do I use an array to retrieve the name and description from the JSON data?
{
"status": {
"timestamp": "2020-10-14T09:04:56.382Z",
"error_code": 0,
"error_message": null,
"elapsed": 8,
"credit_count": 1,
"notice": null
},
"data": {
"1": {
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"category": "coin",
"description": "Bitcoin (BTC) is a cryptocurrency . Users are able to generate BTC through the process of mining. Bitcoin has a current supply of 18,516,718. The last known price of Bitcoin is 11,440.13537699 USD and is down -0.18 over the last 24 hours. It is currently trading on 9569 active market(s) with $22,842,507,797.43 traded over the last 24 hours. More information can be found at https://bitcoin.org/.",
"slug": "bitcoin",
"logo": "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
"subreddit": "bitcoin",
"notice": "",
"tags": [
"mineable",
"pow",
"sha-256",
"store-of-value",
"state-channels"
],
"tag-names": [
"Mineable",
"PoW",
"SHA-256",
"Store of Value",
"State channels"
],
"tag-groups": [
"OTHER",
"CONSENSUS_ALGORITHM",
"CONSENSUS_ALGORITHM",
"PROPERTY",
"PROPERTY"
],
"urls": {
"website": [
"https://bitcoin.org/"
],
"twitter": [],
"message_board": [
"https://bitcointalk.org"
],
"chat": [],
"explorer": [
"https://blockchain.coinmarketcap.com/chain/bitcoin",
"https://blockchain.info/",
"https://live.blockcypher.com/btc/",
"https://blockchair.com/bitcoin",
"https://explorer.viabtc.com/btc"
],
"reddit": [
"https://reddit.com/r/bitcoin"
],
"technical_doc": [
"https://bitcoin.org/bitcoin.pdf"
],
"source_code": [
"https://github.com/bitcoin/"
],
"announcement": []
},
"platform": null,
"date_added": "2013-04-28T00:00:00.000Z",
"twitter_username": "",
"is_hidden": 0
}
}
}
import React, { useEffect, useState } from 'react';
import Axios from 'axios'
import { Link } from 'react-router-dom';
function DetailsScreen(props){
const [cryptoVar, setcryptoList] = useState({name: "", description: ""});
useEffect(() => {
Axios.get(`http://localhost:5000/api/getProducts/${props.match.params.id}`,
{
}).then((response)=>{
console.log(response.data.data );
setcryptoList({
name: response.data.data,
description: response.data.data
});
}).catch(err =>{
console.log(err.response.data);
})
return () => {
}
}, [])
console.log(cryptoVar.description);
return(
<div>
Name: {cryptoVar.name}
Description: {cryptoVar.description}
</div>
);
}
export default DetailsScreen;