首页 技术 正文
技术 2022年11月10日
0 收藏 431 点赞 4,368 浏览 1895 个字

实体类

 public class FlieList
{ public string file_unid { get; set; } public string file_name { get; set; } public object file_md5 { get; set; } public string file_path { get; set; } public string file_ext { get; set; } public string file_createtime { get; set; } public string file_size { get; set; } public string file_state { get; set; } public string file_save_type { get; set; } public string file_belongto { get; set; }
}

  json数据单条:

{
"file_unid":"20170724-7F2A0BE3607DFEE0E134-11",
"file_name":"文档.doc",
"file_md5":null,
"file_path":"/fileark/3496dd7b36ce3b6ef78f33fe64c2ea10.doc",
"file_ext":"doc",
"file_createtime":"2017-07-24 10:46:41",
"file_size":"24064",
"file_state":"0",
"file_save_type":"0",
"file_belongto":"EC388D0A7184CC4EFCC005E8E97B10BB"
}

  json数据多条:

[
{
"file_unid":"20170724-7F2A0BE3607DFEE0E134-11",
"file_name":"文档.doc",
"file_md5":null,
"file_path":"/fileark/3496dd7b36ce3b6ef78f33fe64c2ea10.doc",
"file_ext":"doc",
"file_createtime":"2017-07-24 10:46:41",
"file_size":"24064",
"file_state":"0",
"file_save_type":"0",
"file_belongto":"EC388D0A7184CC4EFCC005E8E97B10BB"
},
{
"file_unid":"20170724-7223CE403B7772D16304-11",
"file_name":"文档1.doc",
"file_md5":null,
"file_path":"/fileark/54e9a264ffe764b0848686d703368e44.doc",
"file_ext":"doc",
"file_createtime":"2017-07-24 10:46:28",
"file_size":"22528",
"file_state":"0",
"file_save_type":"0",
"file_belongto":"EC388D0A7184CC4EFCC005E8E97B10BB"
}
]

  注意:实体类要与json里面字段相对应,实体没有json那么多字段也可以,能跟json匹配的实体类字段会一一赋值。

具体实现:

转单个实体类的实现

1.适用范围 .framework2.0~ .framework3.5之间

 JavaScriptSerializer js = new JavaScriptSerializer();
FlieList file= js.Deserialize<FlieList >(jsonString);

2. 适用范围.framework3.5以下版本不适用

FlieList file= (FlieList)JsonConvert.DeserializeObject(data, typeof(FlieList));

 转集合实体类的实现

1.适用范围 .framework2.0~ .framework3.5之间

 JavaScriptSerializer js = new JavaScriptSerializer();
List<FlieList> file = js.Deserialize<List<FlieList>>(jsonString);

2. 适用范围.framework3.5以下版本不适用

List<FlieList> user = (List<FlieList>)JsonConvert.DeserializeObject(data, typeof(List<FlieList>));

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902