.net 读取json 文件

原文:http://blog.csdn.net/w200221626/article/details/52169250

json 文件 格式:

 1 {
 2     "total": 1,
 3     "page": 1,
 4     "records": 1,
 5     "costtime": "100",
 6     "rows": [
 7         {
 8             "rownum": 1,
 9             "userid": "888",
10             "code": "8888",
11             "account": "8888",
12             "realname": "飞哥",
13             "spell": "ZM",
14             "gender": "",
15             "mobile": "15201956999",
16             "telephone": "021-88888888",
17             "email": "qq@qq.com",
18             "companyid": "10000",
19             "companyname": "上海",
20             "departmentid": "100001",
21             "departmentname": "技术部",
22             "duty": "工程师",
23             "enabled": 1,
24             "logoncount": null,
25             "lastvisit": null,
26             "sortcode": 9000,
27             "createuserid": "admin",
28             "remark": " "
29         }
30     ]
31 }
View Code

读取 json 文件:

 1         public string GetFileJson(string filepath)
 2         {
 3             string json = string.Empty;
 4             using (FileStream fs = new FileStream(filepath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite))
 5             {
 6                 using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312")))
 7                 {
 8                     json = sr.ReadToEnd().ToString();
 9                 }
10             }
11             return json;
12         }
View Code

调用方法 :

1 string filepath = Server.MapPath("~/json1.json");  
2 string json = GetFileJson(filepath);  
View Code

 

转载于:https://www.cnblogs.com/caolingyi/p/8533451.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值