How to connect a local json file and fetch data fro it?


#1

i want to take data from the json file and show it in the the html page.(using the .js/ts file)

for example
my json file is

text.json with the following content

{
"FR30": "this is my text."
}

how to access it and show in the page?
please give code for it …Thanks in advance


#2

Add your JSON file inside of your www folder, then you can fetch the data by using http.get and providing a link to the local file.


#3

Sir in your tutorials you have
this.posts=data.data.children;(inside subscribe)

what should i equal this.post to with respect to the above mentioned json file data.?

And for the record i’ve learnt a lot from your tutorials sir…Thanks :slight_smile:


#4

So when subscribing you’re passing the result into the handler, like this:

(data) => {
    console.log(data);
}

In the tutorial you’re talking about the data object that is passed in is a result from the reddit API, and contains a lot of data. To see the structure of your data just do what I’ve done above, then you will be able to see how it is structured and how to access what you need.


#5

Thanks Sir :relaxed: