zoukankan      html  css  js  c++  java
  • ASP.NET(C#)——JSON解析

    方式:Newtonsoft解析

     Json格式:

    {
        "resultCode""success",
        "resultObject": {
            "results": [{
                "brandId""10000",
                "storageCode""TG0111",
                "vipNumber""13868170777",
                "mobilePhone""13868170777",
            },
            {
                "brandId""10000",
                "storageCode""TG0111",
                "vipNumber""13868170778",
                "mobilePhone""15967917859",
            }],
            "pagination": {
                "startModified""2015-01-01 00:00:00",
                "endModified"null
            }
        },
        "exceptionMessage"null
    }

     Json对象解析:

    JObject obj = JObject.Parse(json);
    string resultCode = obj["resultCode"].ToString();

    Json数组解析:

    对象:

    public class Vip
    {
        public Vip()
        {
            _brandId = "";
            _storageCode = "";
            _vipNumber = "";
            _mobilePhone = "";
        }
        private string _brandId;
        public string BrandId
        {
            get { return _brandId; }
            set { _brandId = value; }
        }
        private string _storageCode;
        public string StorageCode
        {
            get { return _storageCode; }
            set { _storageCode = value; }
        }
        private string _vipNumber;
        public string VipNumber
        {
            get { return _vipNumber; }
            set { _vipNumber = value; }
        }
        private string _mobilePhone;
        public string MobilePhone
        {
            get { return _mobilePhone; }
            set { _mobilePhone = value; }
        }
    }

     解析代码:

    JObject obj = JObject.Parse(json); 

    JArray jlist = JArray.Parse(obj["resultObject"]["results"].ToString());
    Vip vip = new Vip();
    for (int j = 0; j < jlist.Count; j++)
    {
       JObject temp = JObject.Parse(jlist[j].ToString());  

       vip.BrandId = temp["brandId"].ToString();
       vip.StorageCode = temp["storageCode"].ToString();

       vip.VipNumber = temp["vipNumber"].ToString();

       vip.MobilePhone = temp["mobilePhone"].ToString();
       //VipProc vipProc = new VipProc();
       //vipProc.In_Vip(vip);
    }


  • 相关阅读:
    86. Partition List
    2. Add Two Numbers
    55. Jump Game
    70. Climbing Stairs
    53. Maximum Subarray
    64. Minimum Path Sum
    122. Best Time to Buy and Sell Stock II
    以场景为中心的产品设计方法
    那些产品经理犯过最大的错
    Axure教程:如何使用动态面板?动态面板功能详解
  • 原文地址:https://www.cnblogs.com/bluewhy/p/5286512.html
Copyright © 2011-2022 走看看