Wednesday, August 6, 2014

object to jsonObject and string

way to make json object

<script>
var main = new Array();
sub = new Object();    
sub['key1'] = 'value1';
sub['key2'] = 'value2';
sub['key3'] = 'value3';
main[0] = sub;

sub = new Object();    
sub['key1'] = 'value4';
sub['key2'] = 'value5';
sub['key3'] = 'value6';
main[1] = sub;


var jsonObject = {list:main};

alert(JSON.stringify(jsonObject));

</script>

No comments:

Post a Comment