Reputation: 5792
I have variable in javascript which is coming from php by json_encode. While I am psrsing it with JSON.parse(variable). It alert me objects instead of actual result.
CODE:
var a = '<?php echo json_encode($over_branch_array); ?>';
a = JSON.parse(a);
alert(a);
EDIT:
basically I need to map my php array.
a = a.map(function(v){
return { id : v.branch, text : v.branch };
});
If I will do JSON.stringify then I won't be able to do that..
Upvotes: 0
Views: 740
Reputation: 32511
alert
performs a toString
conversion on objects before displaying them. You'll get a result like this.
If you want to view the contents of the object, either console.log
it or JSON.stringify
it.
EDIT:
When I say use JSON.stringify
I mean do it to show what is actually in the object:
alert(JSON.stringify(a));
Upvotes: 1