如何在asp.net中反序列化此JSON

时间:2011-09-02 05:32:54

标签: c# asp.net json

这是我在asp.net中反序列化JSOn的代码,但是它没有用。

    [
        {
            "resultList": [
                {
                    "channelType": "",
                    "duration": "2:29:30",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 1204,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/The-Great-target.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/The-Great-target.jpg",
                    "language": "Hindi",
                    "name": "The Great Target",
                    "productId": 1204,
                    "productMasterId": 1203,
                    "productMasterName": "The Great Target",
                    "productName": "The Great Target",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "2005",
                    "releaseyear": "2005",
                    "showGoodName": "Movies ",
                    "views": 8276
                },
                {
                    "channelType": "",
                    "duration": "2:30:30",
                    "episodeno": 0,
                    "genre": "Romance",
                    "genreList": [
                        "Romance"
                    ],
                    "genres": [
                        {
                            "personName": "Romance"
                        }
                    ],
                    "id": 1144,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/MereSapnoKiRaani.JPG",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/MereSapnoKiRaani.JPG",
                    "language": "Hindi",
                    "name": "Mere Sapnon Ki Rani",
                    "productId": 1144,
                    "productMasterId": 1143,
                    "productMasterName": "Mere Sapnon Ki Rani",
                    "productName": "Mere Sapnon Ki Rani",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "1997",
                    "releaseyear": "1997",
                    "showGoodName": "Movies ",
                    "views": 6472
                },
                {
                    "channelType": "",
                    "duration": "2:34:07",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 1520,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/SATYAMEVAJAYATHE.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/SATYAMEVAJAYATHE.jpg",
                    "language": "Telugu",
                    "name": "Satyameva Jayathe",
                    "productId": 1520,
                    "productMasterId": 1519,
                    "productMasterName": "Satyameva Jayathe",
                    "productName": "Satyameva Jayathe",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "2004",
                    "releaseyear": "2004",
                    "showGoodName": "Movies ",
                    "views": 9897
                },
                {
                    "channelType": "",
                    "duration": "2:39:06",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 9155,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/sabse_bada_mawali.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/sabse_bada_mawali.jpg",
                    "language": "Hindi",
                    "name": "Sabse Bada Mawali",
                    "productId": 9155,
                    "productMasterId": 3451,
                    "productMasterName": "Sabse Bada Mawali",
                    "productName": "Sabse Bada Mawali",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "2007",
                    "releaseyear": "2007",
                    "showGoodName": "Movies ",
                    "views": 18029
                },
                {
                    "channelType": "",
                    "duration": "2:31:00",
                    "episodeno": 0,
                    "genre": "Thriller",
                    "genreList": [
                        "Thriller"
                    ],
                    "genres": [
                        {
                            "personName": "Thriller"
                        }
                    ],
                    "id": 43,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Kyon_292.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Kyon_292.jpg",
                    "language": "Hindi",
                    "name": "Kyon",
                    "productId": 43,
                    "productMasterId": 42,
                    "productMasterName": "Kyon",
                    "productName": "Kyon",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3.5,
                    "releaseYear": "2003",
                    "releaseyear": "2003",
                    "showGoodName": "Movies ",
                    "views": 11558
                },
                {
                    "channelType": "",
                    "duration": "2:16:50",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 13894,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/pyarkasaudagar.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/pyarkasaudagar.jpg",
                    "language": "Hindi",
                    "name": "Pyar Ka Saudagar",
                    "productId": 13894,
                    "productMasterId": 4447,
                    "productMasterName": "Pyar Ka Saudagar",
                    "productName": "Pyar Ka Saudagar",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "1961",
                    "releaseyear": "1961",
                    "showGoodName": "Movies ",
                    "views": 1700
                },
                {
                    "channelType": "",
                    "duration": "1:43:18",
                    "episodeno": 0,
                    "genre": "Thriller",
                    "genreList": [
                        "Thriller"
                    ],
                    "genres": [
                        {
                            "personName": "Thriller"
                        }
                    ],
                    "id": 13238,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/sikandar_movie.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/sikandar_movie.jpg",
                    "language": "Hindi",
                    "name": "Sikandar",
                    "productId": 13238,
                    "productMasterId": 4286,
                    "productMasterName": "Sikandar",
                    "productName": "Sikandar",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "2009",
                    "releaseyear": "2009",
                    "showGoodName": "Movies ",
                    "views": 2165
                },
                {
                    "channelType": "",
                    "duration": "1:10:11",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 1260,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Apoorva%20Ragangal.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Apoorva%20Ragangal.jpg",
                    "language": "Tamil",
                    "name": "Apoorva Ragangal",
                    "productId": 1260,
                    "productMasterId": 1259,
                    "productMasterName": "Apoorva Ragangal",
                    "productName": "Apoorva Ragangal",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "1975",
                    "releaseyear": "1975",
                    "showGoodName": "Movies ",
                    "views": 12906
                },
                {
                    "channelType": "",
                    "duration": "2:21:00",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 1255,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Guna.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Guna.jpg",
                    "language": "Tamil",
                    "name": "Guna",
                    "productId": 1255,
                    "productMasterId": 989,
                    "productMasterName": "Guna",
                    "productName": "Guna",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "2003",
                    "releaseyear": "2003",
                    "showGoodName": "Movies ",
                    "views": 5498
                },
                {
                    "channelType": "",
                    "duration": "2:01:48",
                    "episodeno": 0,
                    "genre": "Drama",
                    "genreList": [
                        "Drama"
                    ],
                    "genres": [
                        {
                            "personName": "Drama"
                        }
                    ],
                    "id": 1247,
                    "imageUrl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Mouna-Ragam_58.jpg",
                    "imageurl": "http://vodimages.bigflicks.com/images/vod/movies/160X100/Mouna-Ragam_58.jpg",
                    "language": "Tamil",
                    "name": "Mouna Ragam",
                    "productId": 1247,
                    "productMasterId": 1246,
                    "productMasterName": "Mouna Ragam",
                    "productName": "Mouna Ragam",
                    "productTypeId": 1,
                    "productTypeName": "Movie",
                    "rating": 3,
                    "releaseYear": "1986",
                    "releaseyear": "1986",
                    "showGoodName": "Movies ",
                    "views": 10833
                }
            ],
            "resultSize": 1171,
            "pageIndex": "1"
        }
    ]

我的课程如下 -

class basicgalary 
{ 
    public Items resultList
    {
        get;
        set;
    }
}

public class Items
{ 
    public string id
    {
        get;
        set;
    } 

    public string imageUrl
    {
        get;
        set;
    } 

    public string imageurl
    {
        get;
        set;
    } 

    public string language
    {
        get;
        set;
    } 

    public string name
    {
        get;
        set;
    } 

    public string productid
    {
        get;
        set;
    } 

    public string productMasterId
    {
        get;
        set;
    } 

    public int rating
    {
        get;
        set;
    } 

    public string releaseYear
    {
        get;
        set;
    } 

    public string releaseyear
    {
        get;
        set;
    } 

    public string showGoodName
    {
        get;
        set;
    } 

    public string views
    {
        get;
        set;
    } 
}

public class common 
{ 
    public string personname
    {
        get;
        set;
    }
} 

我尝试了很多..但我没有得到我想要的答案..所以请帮助我......

3 个答案:

答案 0 :(得分:1)

我还建议使用Json.Net。它非常强大且易于使用。

Json.Net

答案 1 :(得分:1)

.NET Framework提供了易于使用的JavaScriptSerializer Class(在System.Web.Extensions.dll程序集中)。

这里有一个例子:Dictionary to JSON Serialization and Deserialization

答案 2 :(得分:0)

您可以使用JavaScriptConvert.DeserializeObject()。有关详细步骤,请阅读this