C#语言中string格式转json格式

C#语言中string格式转json格式

在C# 编写中发现获取到的string字符串转换成json字符串更容易读取,因此就实验了一下怎么转换成json格式,如获取到的字符串如下图所示,我们现在想读取list中的数据,怎么读呢。

在这里插入图片描述

首先,这里我下载的LitJson.dll,并添加了引用

在这里插入图片描述

在代码中声明
using LitJson;
然后再代码中就可以转换了
string htmlstr = "{"pageSize":20,"currentPage":1,"currentResult":0,"totalRecord":6,"totalPage":1,"list":[{"earthquake_id":"CD20191009234110","isPrepare":1,"isPublish":1,"latitudes":"29.57","regionStatus":1,"depth":"14","isDeleted":0,"ym":"2019-10","longitudes":"104.82","epicenter":"四川内江市威远县","cataId":"CD20191009234110","id":126347,"num_mag":"3.3","region":"四川","orig_time":"2019-10-09 23:41:09","createDate":"2019-10-09 23:52:32"},{"earthquake_id":"CD20191008222149","isPrepare":1,"isPublish":1,"latitudes":"39.84","regionStatus":1,"depth":"10","isDeleted":0,"ym":"2019-10","longitudes":"77.17","epicenter":"新疆喀什地区伽师县","cataId":"CD20191008222149","id":126345,"num_mag":"3.0","region":"新疆","orig_time":"2019-10-08 22:21:49","createDate":"2019-10-08 22:32:32"},{"earthquake_id":"CC20191006184056","isPrepare":1,"isPublish":1,"latitudes":"-21.91","regionStatus":2,"depth":"90","isDeleted":0,"ym":"2019-10","longitudes":"-68.45","epicenter":"智利","cataId":"CC20191006184056","id":126342,"num_mag":"5.6","orig_time":"2019-10-06 18:40:55","createDate":"2019-10-06 19:22:32"},{"earthquake_id":"CC20191005114816","isPrepare":1,"isPublish":1,"latitudes":"52","regionStatus":2,"depth":"130","isDeleted":0,"ym":"2019-10","longitudes":"178.16","epicenter":"拉特群岛","cataId":"CC20191005114816","id":126341,"num_mag":"5.1","orig_time":"2019-10-05 11:48:16","createDate":"2019-10-05 12:22:32"}],"t":{"latitudesMax":90.0,"numMagMin":1.0,"pageSize":20,"numMagMax":10.0,"depthMin":0.0,"longitudesMin":-180.0,"latitudesMin":-90.0,"epicenter":null,"startTime":"2019-10-05 00:00:00","endTime":"2019-10-09 23:59:59","longitudesMax":180.0,"currentPage":1,"depthMax":1000.0}}";
JsonData deJson = LitJson.JsonMapper.ToObject(htmlstr);
deJson = deJson["list"];
for (int num_hisEQ = 0; num_hisEQ < deJson.Count; num_hisEQ++)
{
    JsonData temp_de = deJson[num_hisEQ];
    List<string> history_temp = new List<string>();
    history_temp.Add(temp_de["orig_time"].ToString());
    history_temp.Add(temp_de["longitudes"].ToString());
    history_temp.Add(temp_de["latitudes"].ToString());
    history_temp.Add(temp_de["depth"].ToString());
    history_temp.Add(temp_de["num_mag"].ToString());
    history_temp.Add(temp_de["epicenter"].ToString());
}
转换为json使用起来是不是很简单啊!

上一篇:C#获取动态网页中的数据

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值