javascript - Not getting expected values from JSON -
i trying json values using jquery, code not working expect to. can please give me suggestion on how fix it?
// json response: [{ "private": "8044553.0" }, { "governmentdocs": "98952.0" }, { "officialdocs": "5577356.0" }] $.each($.parsejson(data), function(idx, obj) { privatedocs = obj.private; alert(obj.private); alert(obj.officialdocs); alert(obj.governmentdocs); });
i getting value 8044553.0
, undefined
, 5577356.0
. why showing this?
you have problem in json : [{"private":"8044553.0"}, {"governmentdocs":"98952.0"}, {"officialdocs":"5577356.0"}]
json should :
'[{"private":"8044553.0", "governmentdocs":"98952.0", "officialdocs":"5577356.0"}]'
here working example :
var data ='[{"private":"8044553.0", "governmentdocs":"98952.0", "officialdocs":"5577356.0"}]'; $.each($.parsejson(data), function(idx, obj) { privatedocs=obj.private; alert(obj.private); alert(obj.officialdocs); alert(obj.governmentdocs); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment