C# 新手项目学习5 --Newtonsoft.Json Json解析
来源:互联网 发布:国投瑞银基金知乎 编辑:程序博客网 时间:2024/06/07 10:02
JSON解析
用Newtonsoft.Json.dll 下载 http://json.codeplex.com/
1:简单的单层JSON解析
如: //"{ \"result\": 1, \"adminId\": 2, \"customerId\": 1}"
JObject jobj = JObject.Parse(resultStr); int result = (int)jobj["result"]; int adminId = (int)jobj["adminId"]; int customerId = (int)jobj["customerId"];2:简单的双层解析
如:
JObject jo = JObject.Parse(result); int resulta = (int)jo["result"];JArray jas = (JArray)jo["customers"]; string createTime = jas[0]["createTime"].ToString(); int customerId = (int)jas[0]["customerId"]; int parkingCount = (int)jas[0]["parkingCount"]; int type = (int)jas[0]["type"]; string companyName = jas[0]["companyName"].ToString(); string modifyTime = jas[0]["modifyTime"].ToString();
如果存在内容有
类似这种的,就只要知道rechargeRecord下面有多少个数组就好了。Jraay有一个Count的方法,可以得到个数
JArray jas = (JArray)jo["rechargeRecord"]; int joa = jas.Count(); for (int i = 0; i < joa; i++) { string createTime = (string)jas[i]["createTime"]; DateTime createDate = GetNoralTime(createTime); int insideCarId = (int)jas[i]["insideCarId"]; int customerId = (int)jas[i]["customerId"]; int vChargeRecrodId = (int)jas[i]["vChargeRecrodId"]; int type = (int)jas[i]["type"]; int rechargeRecordId = (int)jas[i]["rechargeRecordId"]; string sql = ""; if (type == 0) sql = "insert into tb_rechargeRecrod values (" + rechargeRecordId + "," + customerId + "," + insideCarId + "," + vChargeRecrodId + ",'" + createDate + "')"; else sql = "update tb_rechargeRecrod set createTime='" + createTime + "' where rechargeRecordId=" + rechargeRecordId; DataBase.UpdateDB(sql); }
这样就可以得到每个数组的数据。。。嘎嘎
嗯。自己瞎搞出来的。感觉怪怪的。
0 0
- C# 新手项目学习5 --Newtonsoft.Json Json解析
- C# 解析JSON -- Newtonsoft.Json
- C# 解析json Newtonsoft.json
- C# newtonsoft.json.dll 解析Json
- C# 使用Newtonsoft.Json解析嵌套json
- C# 低版本Newtonsoft解析JSON数组
- Newtonsoft.Json解析json数据
- C# Newtonsoft json
- C# Newtonsoft.Json 操作
- C#解析Json数据(利用Newtonsoft.Json库)
- 采用Newtonsoft解析JSON字符串
- c# 使用Newtonsoft.Json 对数据进行打包与解析
- 在C# 项目中添加NewtonSoft.json 的引用
- Newtonsoft.Json.DLL 解析Json数据
- MVC Newtonsoft.Json解析JSON字符串
- Maxscript调用Newtonsoft.Json解析Json
- Json解析中文乱码,Newtonsoft.Json
- c#操作json数据使用newtonsoft.json
- 详细讲解transform
- group by
- ImageView 按固定宽度等比例缩放
- RAID-介绍
- 使用JQuery+Struts1.3实现JSON的post传递
- C# 新手项目学习5 --Newtonsoft.Json Json解析
- SSH和MVC的关系
- FlashDevelop快捷键
- Tomcat一点一滴之(三)整合Apache、Nginx
- HDFS--Hadoop分布式文件系统
- 不明白这些错误如何改,求大神指导
- BST与AVL的C++模板实现
- Binary XML file line #2: Error inflating class android.widget
- 使用spring @Scheduled注解执行定时任务