|
What does "Invalid Label" mean in a JSON response, and how can I fix it? |
I recently build an application that returned a JSON object of data based on a select field value. Whilst I was building this I encountered an error using the JavaScript eval() function on my JSON response. I am using the eval() function to parse a string from my JSON response, but firebug is showing a JavaScript error of "Invalid Label".
This is the code:
2 jsonResponse = eval(data);
3 var src = jsonResponse.DATA;
4 });
After having a Google around it appears that the eval function is interpreting the first item in the JSON response as a label, rather than data. By changing the code like this:
We are forcing eval to recognise the data as variable data. Now the JSON to string translation works.
I'll note it down, am sure it will be useful for us.