A
A
Arseniy Sokolovsky2020-07-30 19:10:54
JavaScript
Arseniy Sokolovsky, 2020-07-30 19:10:54

Unable to output text from JSON to HTML. How can I do it?

I have code

$.getJSON( "json/account.json", function(obj) { 
    $.each(obj, function(key, value) { 
        document.getElementById('nickname-menu').innerHTML = value.Name;
  		});
 	});


and JSON
{
    "Name": "Happy",
    "Title": "The Just Dancer",
    "Avatar": "1",
    "Skin": "11"
}


i want to output "Name" from json to html in h1 with id: "nickname-menu"

what did i write wrong in javascript ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DevMan, 2020-07-30
@SokolarGm

why are you iterating over your json?

$.getJSON( "json/account.json", function(obj) { 
    document.getElementById('nickname-menu').innerHTML = obj.Name;
});

V
Valera Karmanov, 2020-07-30
@motokraft

document.getElementById('nickname-menu').innerHTML = value;

L
Let_peace, 2020-08-04
@Let_peace

You can include jQuery and use the following algorithm:

$.getJSON('json/account.json', function (data) {
    var out=data['Name'];
    $('#nickname-menu').html(out);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question