Multi object json access

Multi object json access

by Hilarius Doren

HTML

<h2>Convert a string into a date object.</h2>

<p id="demo"></p>
<p id="demo1"></p>

JavaScript

var text = '{"0" : { "name":"John", "birth":"1986-12-14", "city":"New York"},"1" : { "name1":"John1", "birth1":"1986-12-15", "city1":"New York1"}}';
var obj = JSON.parse(text);
obj[0].birth = new Date(obj[0].birth);
obj[1].birth1 = new Date(obj[1].birth1);
if (!obj.isEmpty){
document.getElementById("demo").innerHTML = obj[0].name + ", " + obj[0].birth; 
document.getElementById("demo1").innerHTML = obj[1].name1 + ", " + obj[1].birth1; 
}