Newtonsoft.Json解析json数据

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string JsonData="{'result':'200','info':[{'_cid':5,'_name':'Iphone4','_parentid':2,'_status':true},{'_cid':7,'_name':'手机外套','_parentid':2,'_status':true},{'_cid':8,'_name':'手机模','_parentid':2,'_status':true}]}";
            WindowsFormsApplication2.BackInfo backinfo = (WindowsFormsApplication2.BackInfo)
                      JsonConvert.DeserializeObject(JsonData, typeof(WindowsFormsApplication2.BackInfo));

            if (backinfo.result == "200")//成功
            {
                List<WindowsFormsApplication2.IphoneClassify> list = backinfo.info;
                Dictionary<int, String> dic = new System.Collections.Generic.Dictionary<int, String>();
                for (int i = 0; i < list.Count; i++)
                {
                    WindowsFormsApplication2.IphoneClassify classify = (WindowsFormsApplication2.IphoneClassify)list[i];
                    dic.Add(classify._cid, classify._name);
                }
                //this.DataList1.DataSource = dic;
                //this.DataList1.DataBind();
            }
            else
            {
                //失败
            }
        }
    }
    /// <summary>
    ///返回JSON属性
    /// </summary>
    [Serializable]
    public class BackInfo
    {
        public BackInfo()
        {

        }
        public String result { get; set; }
        public List<IphoneClassify> info { get; set; }
    }

    /// <summary>
    ///产品类型
    /// </summary>
    [Serializable]
    public class IphoneClassify
    {
        public int _cid { get; set; }
        public string _name { get; set; }
        public int _parentid { get; set; }
        public bool _status { get; set; }

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值