General Question

Javascript 'eval' problem?
I’m trying to do something simple in Javascript, which is to receive JSON data and insert that data into some variables. The line that’s giving me a problem reads like this:
myData = eval(’(’ + value.responseText + ’)’);
That, by the way, is exactly the way that ever example I’ve ever seen, be it in books or on the web, is written. Exactly. Even cut & pasted and just changing the variable name. Whenever I use it I always get a really vague error that says:
syntax error
()
Firefox is only slightly helpful in pointing to the end of the line and I’m assuming that this ass-stupid thing is saying that I’m missing a semicolon. Which, clearly, I am not.
The data I’m getting back to the server is correct. That data is:
{“date”:“2011–01-19”,“title”:“Fixes”,“author”:“Me”,“content”:“Bogus test”,“newsid”:“4”}
I found that I was required to create an array using:
var myData = new Array()
And, indeed, if I do this all manually like this:
var myData = new Array({“date”:“2011–01-15”,“title”:“Fixes”,“author”:“Me”,“content”:“Bogus test”,“newsid”:“4”});
Then my code works perfectly. But this:
var myData = new Array(eval(’(’ + value.responseText + ’)’));
gives me the same () error. If I do this:
var myData = new Array(eval(value.responseText));
then I get an error saying myData[0] is undefined.
If somebody could please tell me what’s wrong I would appreciate it. If someone could point me to a resource, somewhere in the world, that is correct I’d appreciate it.


4 Answers
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.