Thursday, October 2, 2014

Real Quick JSON Example

JSON is better to handle than XML. Was using it in a project so thought to post here,
<div id="dvResult">Loading...</div>

<script>
var data = [
    {"firstName":"Michael","lastName":"Jackson","SSN":"123456789"}, 
    {"firstName":"Barack","Obama":"Smith","SSN":"124456789"},
    {"firstName":"Peter","lastName":"Jackson","SSN":"125456789"}
];

var x = '';

for (i = 0; i < data.length; i++)
{
    x = x + data[i].firstName + " " + data[i].lastName + " " + data[i].SSN + "<br/>";
}

document.getElementById("dvResult").innerHTML = x;

</script>