I'm sending a Json response to an Ajax function in my page. The Json looks something like this:
{"one": 21, "two": 10, "three": 19, "four": 100}
I'm now creating a function to show this inside an <h3>
tag.
Here is what i tried:
$.ajax({
url: $("#container").attr("data-url"),
dataType: 'json',
success: function (data) {
var results = JSON.stringify(data)
$('#items').text(results[0]);
console.log(data)
}
});
The line $('#items').text(results[0]);
is to check if i could loop through the array, but instead of retrieving the first record, it only retrieves the character {
. I'm sure this is because my actual code is treating the json data as a string, instead of an array, because of JSON.stringify
.
How can i convert this to an array, again, so that i can loop through it and perform some other operations?