How can I get the content of url.json, and cast the json to a variable. The content of url.json is pure json format. Thanx

link|improve this question

69% accept rate
Do you try to access a JSONP service? – Fox32 Feb 9 at 10:19
3  
You can't. It will be evaluated as JavaScript and just vanish in the void. – Felix Kling Feb 9 at 10:21
JSON is not a scripting language, so I guess it's not possible this way. – pimvdb Feb 9 at 10:26
feedback

2 Answers

if you use jquery

<script type="text/javascript">
    var json_variable;
    $.getJSON('url.json', function(json){
     json_variable = json;
    });
</script>
link|improve this answer
feedback

Are you aware of the jquery getJSON api? You can use this to download json from an url. Not sure if you can embed some json directly in a script tag, though.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.