user.id=1;
user.name="admin";
$.post("url",{user:user},function(data)//这里的user:user是不是这样写还是直接用{user}
{},"json");
下面来看一个实例
通过网页特效对象封装了数据
var mydata={};
mydata.name=maindata; //maindata是一个js自定义对象alert($.tojson(mydata));
结果是:
{"name":{"fproid":"sss","fname":"ss","fuse":"y","fexp":"ss"}}使用jquery ajax功能:
$.ajax({type:"post", url:"uwktm.do?operate=insertplan",data:$.tojson(mydata),datatype:"json",
error:function (xmlhttprequest, textstatus, errorthrown)
{
alert("添加数据异常" + xmlhttprequest.responsetext);
}, success:function (data) {
return data =="yes" ? true:false;
}, complete:function () {}
});jsp教程文件
*/
bufferedreader br = new bufferedreader(new inputstreamreader(
(servletinputstream) request.getinputstream()));
string line = null;
stringbuilder sb = new stringbuilder();
while ((line = br.readline()) != null) {
sb.append(line);
}
jsonobject jsonobj = jsonobject.fromobject(sb.tostring());
jsonobject objs = jsonobj.getjsonobject("promain");//根据json格式里的 键 得到 值 (是个对象)
uwktmmain mainitem = (uwktmmain) jsonobject.tobean(objs,
uwktmmain.class);//强制转换为java对象