服务器端接受Json数据的绑定实现
1、在方法参数前加上JsonRead<T>的泛型特性
public ActionResult GetData([JsonRead(typeof(PostData))]PostData postData)
2、继承CustomModelBinder类:
public class JsonReadAttribute : CustomModelBinderAttribute
{
private Type type;
public JsonReadAttribute(Type type)
{
this.type = type;
}
public override IModelBinder GetBinder()
{
return new JsonReadModelBinder(type);
}
}
3、其中JsonReadModelBinder实现IModelBinder接口
public class JsonReadModelBinder : IModelBinder
{
private Type type;
public JsonReadModelBinder(Type type)
{
this.type = type;
} public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var request = controllerContext.HttpContext.Request;
request.InputStream.Position = ;
var objs = new object();
using (var s = new GZipStream(request.InputStream, CompressionMode.Decompress))
{
using (var sReader = new StreamReader(s, Encoding.UTF8))
{
string str = sReader.ReadToEnd();
if (type == typeof(PostData))
{
objs = JsonUnit.Deserialize<PostData>(str);
}else if (type == typeof(PostComment))
{
objs = JsonUnit.Deserialize<PostComment>(str);
}//if else 扩展
sReader.Close();
}
}
return objs;
}
服务器端接受Json数据的绑定实现的更多相关文章
- EF+LINQ事物处理 C# 使用NLog记录日志入门操作 ASP.NET MVC多语言 仿微软网站效果(转) 详解C#特性和反射(一) c# API接受图片文件以Base64格式上传图片 .NET读取json数据并绑定到对象
EF+LINQ事物处理 在使用EF的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...
- android客户端从服务器端获取json数据并解析的实现代码
今天总结一下android客户端从服务器端获取json数据的实现代码,需要的朋友可以参考下 首先客户端从服务器端获取json数据 1.利用HttpUrlConnection /** * 从指定的U ...
- (转)android客户端从服务器端获取json数据并解析的实现代码
今天总结一下android客户端从服务器端获取json数据的实现代码,需要的朋友可以参考下 首先客户端从服务器端获取json数据 1.利用HttpUrlConnection 复制代码 ...
- android客户端从服务器端获取json数据并解析的实现代码(重要)
首先客户端从服务器端获取json数据 1.利用HttpUrlConnection /** * 从指定的URL中获取数组 * @param urlPath * @return * @throws Exc ...
- jQuery插件:Ajax将Json数据自动绑定到Form表单
jQuery注册方法的两种常用方式: //jQuery静态方法注册 //调用方法$.a1() $.extend({ a1: function () { console.log("a1&quo ...
- .NET读取json数据并绑定到对象
需要引用的命名空间: 读取的具体应用: this代表本实体(对象),通过PopulateObject,直接将读取到的json数据与对象进行绑定 Json保存的具体应用: 将对象保存为Json JObj ...
- Ajax —— 服务器端发送JSON数据
重点需要解决的问题:服务器端如何构建JSON数据 思考:JavaBean转JSON数据,集合转JSON数据,普通java对象(String,Number)转JSON数据 一.Gson开源jar包 ...
- 在jfinal的Controller中接受json数据
JFinal中接收URL中的参数或者model中的参数是很方便的,但是对于web2.0的网站来说,经常会以json方式提交比较复杂的数据,比如一个查询,包含了各种过滤条件和排序分页,前端脚本可能提交的 ...
- Json数据异步绑定到界面的Table并且自动刷新
转自:http://blog.csdn.net/jianxin1009/article/details/8565828‘ 做Winform习惯了,大家都习惯设置datasource这样的写法. 如果想 ...
随机推荐
- [LeetCode] Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- 玩玩Excel下的Power View
作为微软平台下的数据展示工具,Power View是一个不错的选择.而在Excel 2013下,即使你没有SharePoint的实例那么你也可以玩转它.此篇讲对Excel 2013下的Power Vi ...
- Quartz:Cron Expressions
原文地址:http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontrigger.html 注意: 位也可能是7位, ...
- Java Hour 62 J2EE App 服务器
目前略微瓶颈了,准备换工作. tomcat.weblogic.jboss的区别,容器的作用 Apache 是一个http 服务器. Tomcat 是一web 应用程序服务器,支持部分的j2ee. Jb ...
- Win10 AppBar
<Page.BottomAppBar> <CommandBar x:Name="cmdBar" Background="Transparent" ...
- php获取当前页面的完整url
javascript实现: top.location.href 顶级窗口的地址 this.location.href 当前窗口的地址 php实现: //测试网址: http://localhost/b ...
- bbed的使用--安装及初探
bbed是oracle内部一款用来直接查看和修改数据文件数据的工具,可以直接修改Oracle数据文件块的内容,在一些特殊恢复场景下比较有用. 1.bbed 的安装 在9i/10g中连接生成bbed: ...
- 注解:【无连接表的】Hibernate单向N->1关联
Person与Address关联:单向N->1,[无连接表的] Person.java package org.crazyit.app.domain; import javax.persiste ...
- MapKit地图划线
只要用于获取用户位置都要取得用户授权 #import "ViewController.h" #import <MapKit/MapKit.h> @interface V ...
- CE搜索内存数据的原理
最近发现有朋友在玩游戏时, 使用一款工具来修改游戏的部分数据,作弊的效果, 也就是CE(Cheat Engine),这款工具是 delphi 编写的, 于是好奇, 然后瞬间想到API OpenPr ...