Reputation: 31
Example of JSON file (Hello.json):
[
{
"Name": "Alex Smith",
"User": "1234",
"Description": "Blue eyes"
},
{
This is what I have:
fetch('Hello.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
var information = data.name[0];
$('#information').append(information);
Can someone please explain what I am doing wrong or if there is a better way to do this? Thanks in advance
Upvotes: -1
Views: 118
Reputation: 1
here's a revised code:
fetch('./Hello.json')
.then( response => response.json())
.then( data => {
var information = data[0].Name;
$('#information').append(information)
})
.catch( error => {
throw new error(`Error: ${error}`)
})
Hope this helps :)
Upvotes: 0
Reputation: 328
Try:
var information = data[0].name;
You have an array of objects, so above should work.
Upvotes: 2