Use the three buttons to load three JSON structures: a single object, an array of records, and records plus metadata.
function addLines( target, lines ) {
const $target = $( target ).empty();
$.each(
lines,
function ( index, text ) {
$( "<div>" )
.text( text )
.appendTo( $target );
}
);
}
$( "#b1" ).on( "click", function () {
$.getJSON( "json1.php" )
.done(function ( data ) {
addLines(
"#d1",
$.map(
data,
function ( value, key ) {
return key + " => " + value;
}
)
);
});
});
← Return to the getJSON tutorial
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.