London
London

Reputation: 15284

parsing json response

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?

Upvotes: 1

Views: 3285

Answers (3)

luchaninov
luchaninov

Reputation: 6806

<script type="text/javascript" src="http://www.json.org/json2.js"></script>
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" );

Upvotes: 0

thomasmalt
thomasmalt

Reputation: 1752

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.

Upvotes: 0

Quentin
Quentin

Reputation: 944442

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.

Upvotes: 3

Related Questions