首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

一个json数据的反序列化解决办法

2014-01-01 
一个json数据的反序列化[{id: 6212718,site_id: 24,title: 观音莲花苑风景美图,picurl_orig

一个json数据的反序列化


[
    {
        "id": "6212718",
        "site_id": "24",
        "title": "观音莲花苑风景美图",
        "picurl_orig": "http://aa.xx.com/lvpics/pic/item/ae51f3deb48f8c54b83697693a292df5e1fe7f8a.jpg",
        "picurl": {
            "0": {
                "picurl": "http://img0.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_0",
                "height": 600,
                "width": 800
            },
            "102": {
                "picurl": "http://img4.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_102",
                "height": 76,
                "width": 102
            },
            "140": {
                "picurl": "http://img6.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_140",
                "height": 105,
                "width": 140
            },
            "192": {
                "picurl": "http://img5.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_192",
                "height": 144,
                "width": 192
            },
            "240": {
                "picurl": "http://img4.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_240",
                "height": 180,
                "width": 240
            },
            "310": {
                "picurl": "http://img1.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_310",
                "height": 232,
                "width": 310
            },
            "510": {
                "picurl": "http://img2.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_510",
                "height": 382,
                "width": 510
            },
            "940": {
                "picurl": "http://img0.xxx.com/data/1_fc693ebf4f5601407e273157bf704e97_0",
                "height": 600,
                "width": 800
            }
        },
        "ctg": "xxx",
        "subctg": "xxx",
        "pic_content": "xxx",
        "push_ctg": "",
        "push_time": "0",
        "uid": "0",
        "linkurl_tmp": "",
        "status": "1",
        "like_num": "0",
        "url_md5": "14b1627def45a9b80bb1bee31ea4b05c",


        "regular_title": "",
        "create_at": "1387945307",
        "update_at": "0",
        "from": {
            "link": "http://lvyou.xxx.com/",
            "title": "xx旅游"
        }
    },
    {
        "id": "6212715",
        "site_id": "24",
        "title": "皮尔森风景美图",
        "picurl_orig": "http://aaa.xxx.com/lvpics/pic/item/73ca59102676dc94c2ce7969.jpg",
        "picurl": {
            "0": {
                "picurl": "http://img4.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_0",
                "height": 768,
                "width": 1024
            },
            "102": {
                "picurl": "http://img3.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_102",
                "height": 76,
                "width": 102
            },
            "140": {
                "picurl": "http://img.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_140",
                "height": 105,
                "width": 140
            },
            "192": {
                "picurl": "http://img.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_192",
                "height": 144,
                "width": 192
            },
            "240": {
                "picurl": "http://img2.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_240",
                "height": 180,
                "width": 240
            },
            "310": {
                "picurl": "http://img4.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_310",
                "height": 232,
                "width": 310
            },
            "510": {
                "picurl": "http://img0.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_510",
                "height": 382,
                "width": 510
            },
            "940": {
                "picurl": "http://img4.xxx.com/data/1_0ca4b207b0a7be5fe072e6679833282a_0",
                "height": 768,
                "width": 1024
            }
        },
        "ctg": "旅行",
        "subctg": "旅行|异域",
        "pic_content": "皮尔森简介:皮尔森是捷克西部的经济、文化和运输中心,西捷克州首府。它位于肥沃的皮尔  皮尔森森盆地中心,处在首都布拉格和德国巴伐利亚之间的公路线上,东北距布拉格100公里。人口551870人。皮尔森有“啤酒之乡”的美称。相传在13世纪时,捷克国王瓦茨拉夫决定在此建立...——来自皮尔森旅游攻略",


        "push_ctg": "",
        "push_time": "0",
        "uid": "0",
        "linkurl_tmp": "",
        "status": "1",
        "like_num": "0",
        "url_md5": "0c2ca7580afe53d8e33a4b366e7e2019",
        "regular_title": "",
        "create_at": "1387945320",
        "update_at": "0",
        "from": {
            "link": "http://lvyou.xxx.com/",
            "title": "xx旅游"
        }
    }]



就是这段json,通常我都用newtonsoft.json去来做,新建个实体类,来反序列化。可是这段json上还是是常数的键,请问这种情况怎么办?急急急
[解决办法]
 
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
   JsonTextReader reader = new JsonTextReader(new StringReader(js));
            while (reader.Read())
            {
                if (reader.Value != null)
                    Console.WriteLine("{0}, Value: {1}", reader.TokenType, reader.Value);
                else
                    Console.WriteLine("{0}", reader.TokenType);
            }
            Console.ReadKey(); 

热点排行