惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - MaxIE

jQuery选择器和选取方法 为什么Android的图片质量会比iPhone的差? 百度地图计算两坐标点之间距离计算 - MaxIE .net下BerkeleyDB操作封装C#版(附单元测试) MS SQL SERVER索引优化相关查询 SSD在SQLServer中的应用 Speech两种使用方法 让.net程序自动运行在管理员权限下 “请求的操作无法在使用用户映射区域打开的文件上执行”问题处理 C#随机字符串随机性不足的解決方式(随机数重复) 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序 解决办法 excel中根据单元格背景颜色进行数据筛选(excel2003实现方法) 跨平台加密版 SQLite 3 - wxSQLite3 数据库sql2000错误8908及处理 jQuery2011年年度最佳插件 jQ中文API离线版下载(适用版本1.4.4,1.5,1.5.1,1.5.2,1.6,1.6.1,1.6.2) 方便的CSS和jQuery下拉菜单解决方案 sql2000无法执行查询及未找到提供程序解决办法 - MaxIE SQL Server优化SELECT语句方法
json.net处理复杂json
MaxIE · 2012-12-15 · via 博客园 - MaxIE

-------------JSON字符串---------

{"id":"-1","result":{"relations":[{"ptId":"713990455","game":"风云","gameid":"50","worldid":"1.1","nickname":"贵族≮蓝皓

≯","gender":"0","relation":"1"},{"ptId":"714626904","game":"风云","gameid":"50","worldid":"1.1","nickname":"刘凡

吻","gender":"0","relation":"1"},{"ptId":"719696772","game":"风云","gameid":"50","worldid":"1.1","nickname":"贵族≮杀神

≯","gender":"0","relation":"1"},{"ptId":"713969267","game":"风云","gameid":"50","worldid":"1.1","nickname":"吉米

仔","gender":"0","relation":"1"},{"ptId":"714286741","game":"风云","gameid":"50","worldid":"1.1","nickname":"指定天

下","gender":"0","relation":"1"},{"ptId":"714905671","game":"风云","gameid":"50","worldid":"1.1","nickname":"冰玉※雅

儿","gender":"1","relation":"1"},{"ptId":"719695948","game":"风云","gameid":"50","worldid":"1.1","nickname":"ξψ妹妹

δοο","gender":"1","relation":"1"},{"ptId":"714884563","game":"风云","gameid":"50","worldid":"1.1","nickname":"药王苗子的老

婆","gender":"0","relation":"1"},{"ptId":"714726500","game":"风云","gameid":"50","worldid":"1.1","nickname":"贵族≮Kiss

≯","gender":"0","relation":"32"},{"ptId":"866101129","game":"风云","gameid":"50","worldid":"1.1","nickname":"聂

风","gender":"0","relation":"32"}],"friendCount":"104"}}

这个json字符串可以分为三个类的组合,最外层我命名为results,中间的命名为relationsInfo,最内的命名为Relations,只要明白以上关系就好办了

以下为类定义

----------自定义类---------

[DataContract(Name = "results")]
    public class results
    {

        [DataMember(Name = "id")]
        public string id{get ;set ; }

        [DataMember(Name = "result")]
        public relationsInfo result{get ;  set ;}
    }

      [DataContract]
    public class relationsInfo
    {
        [DataMember(Name = "relations")]
        public Relations[] relations{get; set;}

        [DataMember(Name = "friendCount")]
        public string friendCount{get;set;}
    }

     [DataContract]
    public class Relations
    {
        private string _gender;
       

        [DataMember(Name = "ptId")]
        public string ptId{ get;set;}

        [DataMember(Name = "game")]
        public string game{get;set;}

        [DataMember(Name = "gameid")]
        public string gameid {get; set;}

        [DataMember(Name = "worldid")]
        public string worldid{ get;set;}

        [DataMember(Name = "nickname")]
        public string nickname{  get;set;}

        [DataMember(Name = "gender")]
        public string gender
        {
            get {
                if (_gender == "0")
                {
                    return "男";
                }
                else
                {
                    return "女";
                }
            }
            set {
                this._gender = value;
            }
        }

        [DataMember(Name = "relation")]
        public string relation{get;set ;}

    }

---------------转换方法-----------

 string sRelativeUsersJson; //json来源;

 JsonQueryStringConverter convert = new JsonQueryStringConverter();

 results relations = new results();
 relations = (results)convert.ConvertStringToValue(sRelativeUsersJson, relations.GetType());

//或

DataContractJsonSerializer jsr = new DataContractJsonSerializer(typeof(relationsInfo));
System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(sRelativeUsersJson));
relationsInfo relations = (relationsInfo)jsr.ReadObject(ms);