Десериализация данных JSON в asp.net - PullRequest
0 голосов
/ 07 января 2012

У меня есть некоторые данные JSON, и я хочу преобразовать их в простой текст, ниже приводится содержимое, которое я получаю в формате JSON
</p> <pre><code>{"items":[{"id":1371503932001,"name":"shure_ksm_mics","adKeys":null,"shortDescription":"shure_ksm_mics","longDescription":null,"creationDate":"1325934831982","publishedDate":"1325934831982","lastModifiedDate":"1325937858839","linkURL":null,"linkText":null,"tags":[],"videoStillURL":null,"thumbnailURL":null,"referenceId":null,"length":204130,"economics":"AD_SUPPORTED","playsTotal":null,"playsTrailingWeek":null,"FLVURL":"rtmp:\/\/brightcove.fcod.llnwd.net\/a500\/d19\/&media\/13421268001\/13421268001_1371835938001_shure-ksm-mics&1325955600000&1818a465ec2632081e214f18376d6a4d","renditions":[],"FLVFullLength":{"audioOnly":false,"controllerType":"DEFAULT","displayName":"shure_ksm_mics.flv","encodingRate":1000000,"frameHeight":480,"frameWidth":640,"id":1371835938001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":29068243,"uploadTimestampMillis":1325934831973,"url":"rtmp:\/\/brightcove.fcod.llnwd.net\/a500\/d19\/&media\/13421268001\/13421268001_1371835938001_shure-ksm-mics&1325955600000&1818a465ec2632081e214f18376d6a4d","videoCodec":"ON2","videoContainer":"FLV","videoDuration":204130},"videoFullLength":{"audioOnly":false,"controllerType":"DEFAULT","displayName":"shure_ksm_mics.flv","encodingRate":1000000,"frameHeight":480,"frameWidth":640,"id":1371835938001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":29068243,"uploadTimestampMillis":1325934831973,"url":"rtmp:\/\/brightcove.fcod.llnwd.net\/a500\/d19\/&media\/13421268001\/13421268001_1371835938001_shure-ksm-mics&1325955600000&1818a465ec2632081e214f18376d6a4d","videoCodec":"ON2","videoContainer":"FLV","videoDuration":204130}}],"page_number":0,"page_size":100,"total_count":-1}

iсоздали ниже класса

public class VideoList
{
    public VideoList() { }
    private string _name;
    public string Name
    {
        get
        {
            return _name;
        }
        set 
        {
            value = _name;
        }
    }
}

в настоящее время я просто хочу получить имя.Как это сделать с помощью класса System.Web.Script.Serialization.JavacriptSerializer.

1 Ответ

0 голосов
/ 07 января 2012

Я изменил структуру модели, но это должно работать:

var serializer = new JavaScriptSerializer();
var result = serializer.Deserialize<VideoList>(json);

public class VideoList
{
    public List<Video> Items { get; set; }
}

public class Video
{
    public string Name { get; set;}

    // you can extend this class with additional propertie
    // to get the rest of json data
}
...