Newtonsoft.Json.dll解析json的dll文件使用

要解析的json

//解析前

//解析前
{"orderlist":[{"backPrice":0,"businessId":93,"businessNotes":"","couponNo":"","createTime":{"date":9,"day":1,"hours":15,"minutes":35,"month":1,"seconds":8,"time":1423467308000,"timezoneOffset":-480,"year":115},"customerId":167193,"customerNickname":"","customerRemark":"","dealerType":"","delFlag":"0","distTrue":"","duShuPrice":"","evaluateFlag":"","expressDate":"","expressPrice":11,"fhPrice":"","getGoodsTime":{"date":17,"day":2,"hours":22,"minutes":55,"month":1,"seconds":45,"time":1424184945000,"timezoneOffset":-480,"year":115},"goodslist":[],"invoiceContent":"","invoiceTitle":"","invoiceType":"0","orderCancelRemark":"","orderCancelTime":null,"orderCode":"201502091535081953","orderId":2724,"orderIntegral":0,"orderOldCode":"","orderOldPrice":321,"orderPrePrice":0,"orderPrePriceOrder":0,"orderPrice":321,"orderRemark":"","orderStatus":"3","payId":1,"payTime":{"date":9,"day":1,"hours":15,"minutes":32,"month":1,"seconds":23,"time":1423467143000,"timezoneOffset":-480,"year":115},"sendExpressTime":{"date":10,"day":2,"hours":13,"minutes":30,"month":1,"seconds":37,"time":1423546237000,"timezoneOffset":-480,"year":115},"shippingAddress":"山西路43号省地税直属局","shippingCity":"南京","shippingCounty":"鼓楼区","shippingMobile":"15150512058","shippingPerson":"李玲","shippingPhone":"83633592","shippingPostcode":"210009","shippingProvince":"江苏","shoppingAddrId":1067,"unionPrice":"0.00","vipPrice":"321.00"},{"backPrice":0,"businessId":87,"businessNotes":"","couponNo":"","createTime":{"date":9,"day":1,"hours":11,"minutes":26,"month":1,"seconds":33,"time":1423452393000,"timezoneOffset":-480,"year":115},"customerId":167782,"customerNickname":"","customerRemark":"","dealerType":"","delFlag":"0","distTrue":"","duShuPrice":"199.20","evaluateFlag":"","expressDate":"","expressPrice":0,"fhPrice":"","getGoodsTime":{"date":19,"day":4,"hours":22,"minutes":55,"month":1,"seconds":42,"time":1424357742000,"timezoneOffset":-480,"year":115},"goodslist":[],"invoiceContent":"","invoiceTitle":"","invoiceType":"0","orderCancelRemark":"","orderCancelTime":null,"orderCode":"201502091126333935","orderId":2719,"orderIntegral":0,"orderOldCode":"","orderOldPrice":199.2,"orderPrePrice":0,"orderPrePriceOrder":0,"orderPrice":199.2,"orderRemark":"","orderStatus":"3","payId":1,"payTime":{"date":11,"day":3,"hours":11,"minutes":17,"month":1,"seconds":19,"time":1423624639000,"timezoneOffset":-480,"year":115},"sendExpressTime":{"date":12,"day":4,"hours":11,"minutes":24,"month":1,"seconds":47,"time":1423711487000,"timezoneOffset":-480,"year":115},"shippingAddress":"草场门大街88号江苏建设大厦2楼计划财务处","shippingCity":"南京","shippingCounty":"鼓楼区","shippingMobile":"18205088909","shippingPerson":"陈明伟","shippingPhone":"","shippingPostcode":"","shippingProvince":"江苏","shoppingAddrId":1130,"unionPrice":"0.00","vipPrice":""},{"backPrice":0,"businessId":93,"businessNotes":"","couponNo":"","createTime":{"date":9,"day":1,"hours":11,"minutes":11,"month":1,"seconds":25,"time":1423451485000,"timezoneOffset":-480,"year":115},"customerId":165780,"customerNickname":"","customerRemark":"","dealerType":"","delFlag":"0","distTrue":"","duShuPrice":"","evaluateFlag":"","expressDate":"","expressPrice":8,"fhPrice":"","getGoodsTime":{"date":17,"day":2,"hours":22,"minutes":55,"month":1,"seconds":45,"time":1424184945000,"timezoneOffset":-480,"year":115},"goodslist":[],"invoiceContent":"","invoiceTitle":"","invoiceType":"0","orderCancelRemark":"","orderCancelTime":null,"orderCode":"201502091111253041","orderId":2718,"orderIntegral":0,"orderOldCode":"","orderOldPrice":214,"orderPrePrice":0,"orderPrePriceOrder":0,"orderPrice":214,"orderRemark":"","orderStatus":"3","payId":1,"payTime":{"date":9,"day":1,"hours":11,"minutes":18,"month":1,"seconds":18,"time":1423451898000,"timezoneOffset":-480,"year":115},"sendExpressTime":{"date":10,"day":2,"hours":13,"minutes":31,"month":1,"seconds":16,"time":1423546276000,"timezoneOffset":-480,"year":115},"shippingAddress":"亭湖区黄海中路1号翰香花园1号楼705室13851180736","shippingCity":"盐城","shippingCounty":"盐城市","shippingMobile":"13851057736","shippingPerson":"仇玉海。晏泉","shippingPhone":"","shippingPostcode":"","shippingProvince":"江苏","shoppingAddrId":1387,"unionPrice":"0.00","vipPrice":"214.00"}],"status":"A001"}

个人用来记忆的,高手勿喷

1,开始解析

//ret表示要解析的json
var t = Newtonsoft.Json.JsonConvert.DeserializeObject(ret).ToString();

2,解析后

{
  "orderlist": [
    {
      "backPrice": 0,
      "businessId": 93,
      "businessNotes": "",
      "couponNo": "",
      "createTime": {
        "date": 9,
        "day": 1,
        "hours": 15,
        "minutes": 35,
        "month": 1,
        "seconds": 8,
        "time": 1423467308000,
        "timezoneOffset": -480,
        "year": 115
      },
      "customerId": 167193,
      "customerNickname": "",
      "customerRemark": "",
      "dealerType": "",
      "delFlag": "0",
      "distTrue": "",
      "duShuPrice": "",
      "evaluateFlag": "",
      "expressDate": "",
      "expressPrice": 11,
      "fhPrice": "",
      "getGoodsTime": {
        "date": 17,
        "day": 2,
        "hours": 22,
        "minutes": 55,
        "month": 1,
        "seconds": 45,
        "time": 1424184945000,
        "timezoneOffset": -480,
        "year": 115
      },
      "goodslist": [],
      "invoiceContent": "",
      "invoiceTitle": "",
      "invoiceType": "0",
      "orderCancelRemark": "",
      "orderCancelTime": null,
      "orderCode": "201502091535081953",
      "orderId": 2724,
      "orderIntegral": 0,
      "orderOldCode": "",
      "orderOldPrice": 321,
      "orderPrePrice": 0,
      "orderPrePriceOrder": 0,
      "orderPrice": 321,
      "orderRemark": "",
      "orderStatus": "3",
      "payId": 1,
      "payTime": {
        "date": 9,
        "day": 1,
        "hours": 15,
        "minutes": 32,
        "month": 1,
        "seconds": 23,
        "time": 1423467143000,
        "timezoneOffset": -480,
        "year": 115
      },
      "sendExpressTime": {
        "date": 10,
        "day": 2,
        "hours": 13,
        "minutes": 30,
        "month": 1,
        "seconds": 37,
        "time": 1423546237000,
        "timezoneOffset": -480,
        "year": 115
      },
      "shippingAddress": "山西路43号省地税直属局",
      "shippingCity": "南京",
      "shippingCounty": "鼓楼区",
      "shippingMobile": "15150512058",
      "shippingPerson": "李玲",
      "shippingPhone": "83633592",
      "shippingPostcode": "210009",
      "shippingProvince": "江苏",
      "shoppingAddrId": 1067,
      "unionPrice": "0.00",
      "vipPrice": "321.00"
    },
    {
      "backPrice": 0,
      "businessId": 87,
      "businessNotes": "",
      "couponNo": "",
      "createTime": {
        "date": 9,
        "day": 1,
        "hours": 11,
        "minutes": 26,
        "month": 1,
        "seconds": 33,
        "time": 1423452393000,
        "timezoneOffset": -480,
        "year": 115
      },
      "customerId": 167782,
      "customerNickname": "",
      "customerRemark": "",
      "dealerType": "",
      "delFlag": "0",
      "distTrue": "",
      "duShuPrice": "199.20",
      "evaluateFlag": "",
      "expressDate": "",
      "expressPrice": 0,
      "fhPrice": "",
      "getGoodsTime": {
        "date": 19,
        "day": 4,
        "hours": 22,
        "minutes": 55,
        "month": 1,
        "seconds": 42,
        "time": 1424357742000,
        "timezoneOffset": -480,
        "year": 115
      },
      "goodslist": [],
      "invoiceContent": "",
      "invoiceTitle": "",
      "invoiceType": "0",
      "orderCancelRemark": "",
      "orderCancelTime": null,
      "orderCode": "201502091126333935",
      "orderId": 2719,
      "orderIntegral": 0,
      "orderOldCode": "",
      "orderOldPrice": 199.2,
      "orderPrePrice": 0,
      "orderPrePriceOrder": 0,
      "orderPrice": 199.2,
      "orderRemark": "",
      "orderStatus": "3",
      "payId": 1,
      "payTime": {
        "date": 11,
        "day": 3,
        "hours": 11,
        "minutes": 17,
        "month": 1,
        "seconds": 19,
        "time": 1423624639000,
        "timezoneOffset": -480,
        "year": 115
      },
      "sendExpressTime": {
        "date": 12,
        "day": 4,
        "hours": 11,
        "minutes": 24,
        "month": 1,
        "seconds": 47,
        "time": 1423711487000,
        "timezoneOffset": -480,
        "year": 115
      },
      "shippingAddress": "草场门大街88号江苏建设大厦2楼计划财务处",
      "shippingCity": "南京",
      "shippingCounty": "鼓楼区",
      "shippingMobile": "18205088909",
      "shippingPerson": "陈明伟",
      "shippingPhone": "",
      "shippingPostcode": "",
      "shippingProvince": "江苏",
      "shoppingAddrId": 1130,
      "unionPrice": "0.00",
      "vipPrice": ""
    },
    {
      "backPrice": 0,
      "businessId": 93,
      "businessNotes": "",
      "couponNo": "",
      "createTime": {
        "date": 9,
        "day": 1,
        "hours": 11,
        "minutes": 11,
        "month": 1,
        "seconds": 25,
        "time": 1423451485000,
        "timezoneOffset": -480,
        "year": 115
      },
      "customerId": 165780,
      "customerNickname": "",
      "customerRemark": "",
      "dealerType": "",
      "delFlag": "0",
      "distTrue": "",
      "duShuPrice": "",
      "evaluateFlag": "",
      "expressDate": "",
      "expressPrice": 8,
      "fhPrice": "",
      "getGoodsTime": {
        "date": 17,
        "day": 2,
        "hours": 22,
        "minutes": 55,
        "month": 1,
        "seconds": 45,
        "time": 1424184945000,
        "timezoneOffset": -480,
        "year": 115
      },
      "goodslist": [],
      "invoiceContent": "",
      "invoiceTitle": "",
      "invoiceType": "0",
      "orderCancelRemark": "",
      "orderCancelTime": null,
      "orderCode": "201502091111253041",
      "orderId": 2718,
      "orderIntegral": 0,
      "orderOldCode": "",
      "orderOldPrice": 214,
      "orderPrePrice": 0,
      "orderPrePriceOrder": 0,
      "orderPrice": 214,
      "orderRemark": "",
      "orderStatus": "3",
      "payId": 1,
      "payTime": {
        "date": 9,
        "day": 1,
        "hours": 11,
        "minutes": 18,
        "month": 1,
        "seconds": 18,
        "time": 1423451898000,
        "timezoneOffset": -480,
        "year": 115
      },
      "sendExpressTime": {
        "date": 10,
        "day": 2,
        "hours": 13,
        "minutes": 31,
        "month": 1,
        "seconds": 16,
        "time": 1423546276000,
        "timezoneOffset": -480,
        "year": 115
      },
      "shippingAddress": "亭湖区黄海中路1号翰香花园1号楼705室13851180736",
      "shippingCity": "盐城",
      "shippingCounty": "盐城市",
      "shippingMobile": "13851057736",
      "shippingPerson": "仇玉海。晏泉",
      "shippingPhone": "",
      "shippingPostcode": "",
      "shippingProvince": "江苏",
      "shoppingAddrId": 1387,
      "unionPrice": "0.00",
      "vipPrice": "214.00"
    }
  ],
  "status": "A001"
}

3,根据解析后的json,用JObject.Parse(t)[]获取对应数据

List<JToken> list = JObject.Parse(t)["orderlist"].ToList();

4,循环list

时间: 2024-10-05 06:16:12

Newtonsoft.Json.dll解析json的dll文件使用的相关文章

.net使用Newtonsoft.Json.dll解析json过程的几种特殊情况处理

.net用来解析json的库 Newtonsoft.Json.dll 按理说已十分强大,但调用人家的json总有意想不到的情况发生,你没办法要求别人传给你标准的json字符串给你下面是我遇到的几种情况及解决方法:情况1,字段中包含英文引号:{"title": "这个"笑话"一点也不好笑","flag": 0}情况2,{}开头结尾的字段前后有引号:{"content" : "{"微信&qu

Android原生生成JSON与解析JSON

JSON数据是一种轻量级的数据交换格式,在Android中通常应用于客户端与服务器交互之间的数据传输.像现在在网上有很多解析JSON数据的jar包,但是归根到底用的都是Android原生解析JSON数据的方式,所以掌握Android原生解析JSON数据的方法相当重要. 下面分为生成JSON数据和解析JSON数据,所用的包是org.json (1)生成JSON数据方法: 比如要生成一个这样的json文本 { "phone" : ["12345678", "8

JSON.parse 解析json字符串时,遇换行符报错

今天遇到后台返回的json字符串转对象时报错了,发现有个textarea提交的字段里有换行符. 错误原因:JSON.parse转json字符串时遇到一些特殊字符需要先转义,如图所示 可以用str.replace(/\n/g,"\\\\n")转义,'\\'转成单个'\','\\n'转成'\n',最后转成'\\n'这样就可以用parse转成对象时变为'\n',取出的字符串设置到html文本中\n被解析为换行. ECMA Script注明json字符串中需要转义的字符: 测试: 1.var

JSON序列化 解析JSON

var book = { title : "JavaScript", authors : ["Nickolas . Zakas"], edition : 3, year : 2011 }, jsonText; JSON序列化 //简单序列化 SON.stringify接受3个参数 第一个需要序列化的对象 第二个参数是一个过滤器 可以是数组也可以是一个函数 jsonText = JSON.stringify( book ); //过滤 结果只包含过滤器中的字段 jso

GO语言练习:构建json 和 解析JSON 实例

本文介绍如何使用Go语言自带的库把对象转换为JSON格式,并在channel中进行传输后,并把JSON格式的信息转换回对象. 1.Go语言的JSON 库 Go语言自带的JSON转换库为 encoding/json 1.1)其中把对象转换为JSON的方法(函数)为 json.Marshal(),其函数原型如下 func Marshal(v  interface{}) ([]byte, error) 也就是说,这个函数接收任意类型的数据 v,并转换为字节数组类型,返回值就是我们想要的JSON数据和一

post请求获取json数据 解析json数据

<script> window.onload = function () { var str; // console.log(@ViewBag.ID); $.post("/ServiceBills/ServiceBills/UpdateA", { id: @ViewBag.ID}, function (data) { for (var attr in data) { // console.log(attr);//name,age,gender //console.log(d

kettle 利用 HTTP Client 获取猫眼电影API近期上映相关信息,并解析json输出为Excel文件

前言 Kettle 除了常规的数据处理之外,还可以模拟发送HTTP client/post ,REST client. 实验背景 这周二老师布置了一项实验: 建立一个转换,实现一个猫眼API热映电影的json,生成为xls文件. 猫眼的热门电影接口为:?http://m.maoyan.com/#movie,从里面找到API接口:http://m.maoyan.com/ajax/movieOnInfoList.需要获取里面的:电影名.评分.主演.信息. 处理流程 我使用的是kettle的HTTP

【转】c# 解析JSON的几种办法

http://www.cnblogs.com/ambar/archive/2010/07/13/parse-json-via-csharp.html 刚开始只是想找一个转换JSON数组的方法,结果在MSDN翻到一大把. 搜索过程中免不了碰到一大堆名词:WCF => DataContract => DataMember => DataContractJsonSerializer,然后就是不停的引入命名空间. 这一段经历,立即让我就联想到了上面引用的这句存在于某小说里面巫师的话语.静态语言真

【IOS开发之Objective-C】Json的解析 一

一.什么是Json? 关于Json的解释还是看百度百科是怎么解释的<百度百科---JSON>,这里还是比较专业的.首先我们已经知道了我们对象是什么也知道一些它的基本格式(百度百科有说明). 我们也来看看我保存在本地的一个Json文件,来具体分析一下它的格式. 先选择左上角的"Outline"模式,我们看见从左到右就是这么三列,分别是"Type"---类型,"Value"---值和"Name"---名字.有的&quo