[求帮助]C# 反序列化Json字符串

.Net技术 码拜 9年前 (2016-07-12) 1705次浏览
{
“assets”:{
“res/animation/effcet_ui_renwuzhaomu_a.atlas”:{
“md5″:”4c0575628723e1635ec8be36acf88a2a”,
“size”:2308
},
“res/animation/effcet_ui_renwuzhaomu_a.png”:{
“md5″:”d85a63d08320f1ed0e57d14a29f2def2”,
“size”:149834
},
“res/animation/effcet_ui_renwuzhaomu_a.skel”:{
“md5″:”7be6748113adfb14507f2d3723592c4e”,
“size”:2781
},
“res/animation/effcet_ui_renwuzhaomu_b.atlas”:{
“md5″:”d70b08f984191603dd3ab07c9eac1132”,
“size”:4366
},
“res/animation/effcet_ui_renwuzhaomu_b.png”:{
“md5″:”c6ee22d650f450b3912843dba8dbffd9”,
“size”:263839
},
“res/animation/effcet_ui_renwuzhaomu_b.skel”:{
“md5″:”4d05f68fedf81911bb74789a882faf8d”,
“size”:4373
},
“res/animation/effcet_ui_renwuzhaomu_c.atlas”:{
“md5″:”6db21989f9e51f2bc521b5a07392161c”,
“size”:4366
},
“res/animation/effcet_ui_renwuzhaomu_c.png”:{
“md5″:”73a035f79f18434e8bf63c3302a1a8f9”,
“size”:287463
},
“res/animation/effcet_ui_renwuzhaomu_c.skel”:{
“md5″:”41ad60fbbf8d55774cbf75e62d9afdb0”,
“size”:4373
},
“res/animation/effec_ui_changxingliubian.atlas”:{
“md5″:”40a4b44d7691dedc81856377921b3f83”,
“size”:732
},
“res/animation/effec_ui_changxingliubian.png”:{
“md5″:”01fc15228c06ac011dfac2b848473a06”,
“size”:3711
},
“res/animation/effec_ui_changxingliubian.skel”:{
“md5″:”03f6c6b0e50ffce849d6239ec7c8e2bc”,
“size”:743
},
“res/animation/effect_Bossmodi_nuji.atlas”:{
“md5″:”cc3e52194acd74affe4bb865073017ed”,
“size”:2781
},
“res/animation/effect_Bossmodi_nuji.png”:{
“md5″:”d32625fa7805615af1c18e590633da87”,
“size”:185421
},
“res/animation/effect_Bossmodi_nuji.skel”:{
“md5″:”efbfc5b3f7b3f6dd7112ecf72580ec33”,
“size”:2141
},
“res/animation/effect_Bossmodi_pugong.atlas”:{
“md5″:”a12923fe6b2b1d45b9fb1842a5f28518”,
“size”:1292
},
“res/animation/effect_Bossmodi_pugong.png”:{
“md5″:”ae4c8b058d2d0e3d3a289d6a142a2b78”,
“size”:84422
}
}
像这样的一个Json字符串要怎么建立助手类,来进行反序列化呢?第一次接触到这样的代码,实在不知道该怎么建立,望各位大大指点一二。
解决方案

40

var path = System.IO.Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.json");
var s = System.IO.File.ReadAllText(path);
Console.WriteLine(s);
var info = new
{
    md5 = "",
    size = 0,
};
var obj = new
{
    assets = new Dictionary<string, object>()
    {
        { "", info },
    },
};
try
{
    dynamic result = JsonConvert.DeserializeAnonymousType(s, obj);
    foreach (KeyValuePair<string, dynamic> item in result.assets)
    {
        Console.WriteLine("{0}", item.Key);
        Console.WriteLine("    md5: {0}", item.Value.md5);
        Console.WriteLine("   size: {0}", item.Value.size);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明[求帮助]C# 反序列化Json字符串
喜欢 (0)
[1034331897@qq.com]
分享 (0)