Pregunta

I am working on a project and I was not able to figure out how to do this. I have a json file and need to assign it to a js variable to use the protovis visualization tools.

I tried searching on google but could not find any. Please let me know if someone knew how to do this. Thanks!

¿Fue útil?

Solución

Use jQuery's parseJSON().

Description: Takes a well-formed JSON string and returns the resulting JavaScript object. version added: 1.4.1jQuery.parseJSON( json ) jsonThe JSON string to parse. Passing in a malformed JSON string may result in an exception being thrown.

Otros consejos

If you're getting the file from your server via the XMLHttpRequest object, you can parse the json using the JSON.parse function:

var myJson = JSON.parse(response);

For browsers that don't support the JSON object you can get a library for it here: http://www.json.org/js.html

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top