"Testing JSON parsing"
Bootstrap 3.0.0 Snippet by victorgaldamezstarshot

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div id="contenido" class="col-md-offset-4 col-md-4"> Este contenido se reemplazará al parsear el jsonText </div> <hr/> <button class="col-md-offset-4 col-md-4" onclick="javascript:pulsado()">Púlsame</button> </div> </div>
#contenido { border:solid 1px black; margin-top:15px; }
var jsonText = '{ "expense" : ' + ' [' + ' { "account":"1" , "expense":{' + ' "monthlyExpense" : [' + ' {"id" : "16-11", "amount" : "$1.00"}, ' + ' {"id" : "16-12", "amount" : "$2.00"}], ' + ' "monthSelectionOptions" : [' + ' {"16-11", "November"}, ' + ' {"16-12", "December"}]}' + ' },' + ' { "account":"2" , "monthlyExpense" : [' + ' {"id" : "16-11", "amount" : "$3.00"},' + ' {"id" : "16-12", "amount" : "$4.00"}]' + ' },' + ' { "account":"3" , "monthlyExpense" : [' + ' {"id" : "16-11", "amount" : "$5.00"}, ' + ' {"id" : "16-12", "amount" : "$6.00"}] ' + ' }' + ' ]' + '}'; function pulsado() { //Parse the jsonText to test it is well formed var accountsInfo = JSON.parse(jsonText); //alert(accountsInfo.expense[0].monthlyExpense[0].id); //Then, use the JavaScript built-in function JSON.parse() to convert the string $('#contenido').html(JSON.stringify(accountsInfo)); }

Related: See More


Questions / Comments: