Вопрос

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!

Это было полезно?

Решение

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top