码迷,mamicode.com
首页 > Web开发 > 详细

Json 、 Jsonp

时间:2016-05-06 19:36:57      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

SONP is simply a hack to allow web apps to retrieve data across domains. It could be said that it violates the Same Origin Policy (SOP).

The way it works is by using Javascript to insert a "script" element into your page. Therefore, you need a callback function. If you didn‘t

have one, your Javascript would have no way to access the JSON object. But by using JSONP, your Javascript code can call the callback

function. So you must specify the callback name. So your function might look like this:

private static String getJSONPObject(String callback, String s) throws JSONException {
    return callback + "(" + new JSONObject(s) + ")";
}


json格式:
{
    "message":"获取成功",
    "state":"1",
    "result":{"name":"工作组1","id":1,"description":"11"}
}
jsonp格式:
callback({
    "message":"获取成功",
    "state":"1",
    "result":{"name":"工作组1","id":1,"description":"11"}
})

Jquery插件:
https://github.com/congmo/jquery-jsonp

Json 、 Jsonp

标签:

原文地址:http://www.cnblogs.com/yuyutianxia/p/5466699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!