开发者

parsing json response

开发者 https://www.devze.com 2023-01-18 18:03 出处:网络
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?To answer the question you asked: The

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?


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.


<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" );


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消