views:

68

answers:

1

I have a json string that when I put it into the eval function it only returns the last object in the string. Anyone possibly know why

A: 

This is what happening I guess:

<script>
 alert(eval("{firstname: 'Ramiz'; lastname: 'Uddin'}"));
</script>

This will prompt you the last value "Uddin". And a fix of the above script can be:

<script type="text/javascript">
 alert(eval({"firstname": "Ramiz", "lastname": "Uddin"}));
</script>

So, my guess is you should look into your JSON script which might have problems.

Ramiz Uddin
Thanks you were right, the problems was that I had multiple objects being returned from php so I had to separate each of those objects into separate strings and then the function worked perfectly
Daquan Hall