views:

39

answers:

3

I'm calling a REST webservice and getting JSON format as a result. I'm calling rest service from another domain than mine. How can I parse this?

+2  A: 

To answer the question you asked: There is a long list of parsers, including several for JavaScript, at the bottom of http://json.org/

If your question is actually: "How can I read JSON data from another domain with client side JavaScript in the browser?", then you can either fetch it using a proxy on the same domain as the page, or you can provide the data using JSON-P instead.

David Dorward
upvote for answering both questions.
Jonathan Fingland
A: 

Are you getting the json result? Most implementations have protection agains cross site scripting and will only allow a request back to the original host of a page.

Could you please post some example code for your current implementation.

thomasmalt
A: 
<script type="text/javascript" src="http://www.json.org/json2.js"&gt;&lt;/script&gt;
var myObject = JSON.parse(myJSONtext);

or use jQuery

$.getJSON('http://twitter.com/users/usejquery.json?callback=?', function(json) {
    alert(json.followers_count);
});

if you need only parsing jQuery also can do this:

var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );
how