我在.NET中使用这种方法使用JSON对象(两种方式)在客户端和服务器之间来回传递数据.我真的很喜欢这个方法,我希望用web2py做类似的事情.Web2py支持返回json对象并支持jsonrpc.但是我没有能够解析JSON对象.我的客户电话看起来像这样:
var testObject = {};
testObject.value1 = "value1value!";
testObject.value2 = "value2value!";
var DTO = { 'testObject' : testObject };
var data = $.toJSON(DTO); //Using the toJSON plugin by Mark Gibson
$.ajax({
type: 'POST',
url: '/MyWeb2PyApp/MyController/jsontest.json',
contentType: "application/json; charset=utf-8",
data: data,
dataType: 'json',
success: function(data){ alert('yay'); }
});
Run Code Online (Sandbox Code Playgroud)
我在jsontest动作中尝试了很多东西,没有任何效果.
有没有人能够完成类似的事情?
非常感激.
有多种方式.在你的情况下,最简单的事情是
def jsontest():
import gluon.contrib.simplejson
data = gluon.contrib.simplejson.loads(request.body.read())
return dict()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5647 次 |
| 最近记录: |