zoukankan      html  css  js  c++  java
  • wp8 json2csharp


    string jsonData = "{"result":"600","data":{"items":[{"no":"111","uid":"3333333"},{"no":"2222","uid":"44444444"}]},"head":{"server":"api.baidu.cn"}}";

    JObject jsonObj = JObject.Parse(jsonData);
    string name = jsonObj["result"].ToString();
    string province = ((JObject)jsonObj["head"])["server"].ToString();

    var jo = JObject.Parse(jsonData)["data"];
    if (jo.ToString() == "")
    new SearchLoveModel();

    Data list = new Data();
    Item status = null;
    var jItems = jo["items"];
    if (jItems != null)
    {
    foreach (var j in jItems.Children())
    {
    status = j.ToObject<Item>();

    if (!string.IsNullOrEmpty(status.No))
    {
    status.No = "序号" + status.No;
    }
    if (!string.IsNullOrEmpty(status.UId))
    {
    status.UId = "账号" + status.UId;
    }
    list.items.Add(status);
    }
    }

    第二种方法

    SearchLoveModel info = new SearchLoveModel();
    using(MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
    {
    DataContractJsonSerializer ser = new DataContractJsonSerializer(info.GetType());
    info = ser.ReadObject(ms) as SearchLoveModel;
    }

    model

    [DataContract]
    public class Head
    {
    [DataMember]
    public string server { get; set; }
    }
    [DataContract]
    public class Item
    {
    [DataMember]
    public string no { get; set; }
    [DataMember]
    public string uid { get; set; }
    }
    [DataContract]
    public class Data
    {
    public Data()
    {
    items = new List<Item>();
    }
    [DataMember]
    public List<Item> items { get; set; }
    }
    [DataContract]
    public class SearchLoveModel
    {
    [DataMember]
    public string result { get; set; }
    [DataMember]
    public Head head { get; set; }
    [DataMember]
    public Data data { get; set; }
    }

    http://json2csharp.com/#

    http://www.cnblogs.com/pen-ink/archive/2011/10/06/2199715.html

    http://www.cnblogs.com/huizhang212/p/MetroJson.html

    http://wenwen.soso.com/z/q181676143.htm

  • 相关阅读:
    mysql批量插入数据的基类
    mount命令解析
    常用linux命令记录
    转载一篇大神的博客文章
    linux查看网卡状态
    centos7配置网卡绑定
    coentos7安装python3
    阿里云ecs 硬盘在线扩容
    centos7安装redis5
    centos7 rpm安装nginx
  • 原文地址:https://www.cnblogs.com/luquanmingren/p/3562247.html
Copyright © 2011-2022 走看看