Reputation: 4113
i haven't used json before . When i am using eval function on json response than it gives me error of missing ']'. My json is as follows
[{"name":"154.jpg","size":620888,"type":"image\/jpeg","url":"\/active\/components\/com_mtree\/img\/listings\/o\/Tulips.jpg","thumbnail_url":"\/active\/components\/com_mtree\/img\/listings\/s\/Tulips.jpg","delete_url":"\/active\/components\/com_mtree\/img\/listings\/upload.php?file=Tulips.jpg","delete_type":"DELETE"}]
is this any error in this json. in javascript i am using this
var myObject = eval('(' + data + ')');
Upvotes: -1
Views: 178
Reputation: 30530
Why are you prepending/appending brackets to it? As long as its a string, it works fine:
var x= '[{"name":"154.jpg","size":620888,"type":"image\/jpeg","url":"\/active\/components\/com_mtree\/img\/listings\/o\/Tulips.jpg","thumbnail_url":"\/active\/components\/com_mtree\/img\/listings\/s\/Tulips.jpg","delete_url":"\/active\/components\/com_mtree\/img\/listings\/upload.php?file=Tulips.jpg","delete_type":"DELETE"}]';
alert(eval(x));
See http://jsfiddle.net/gCE25/1/
This sort of thing is good if you are learning, however, I would echo @Quentin's sentiments - use a proper JSON Parser.
Upvotes: 0
Reputation: 944528
When i am using eval function
Don't do that. Use a real JSON parser.
it gives me error of missing ']'.
It shouldn't do, since the JSON is valid. You might be using it wrong, but you didn't show any code so it is hard to say. Using a real JSON parser is likely to help with that anyway.
Upvotes: 0