-1

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 + ')'); 
2
  • Could you post your code with the actual call to eval in please? Commented May 26, 2011 at 11:58
  • No, the JSON sample is fine. Please give more context, i.e. a larger sample, and the JavaScipt code that's failing. Commented May 26, 2011 at 12:00

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

var myObject = eval('(' + data + ')'); i am using this
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.