当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Unable to deserialize a json object

问题描述:

I'm using JavaScriptSerializer and when I try to deserialize a JSON object as

Json.Deserialize<List<HeyWatchVideo>>(Request("video"));

I get following Exception:

MissingMethodException: No parameterless constructor defined for type of 'System.String'.

I tried matching my .NET classes, and the types of their properties just as close to my json object, but still getting above exception

My JSON object:

[{

"url": "http://media.heywatch.com.s3.amazonaws.com/14/14/a0f356a48381092e6e2a34021ce86b19/11002247",

"specs": {

"size": 3808,

"video": {

"fps": 11.63,

"height": 360,

"length": 61,

"width": 640,

"aspect": 1.78,

"codec": "mpeg4",

"container": "mov",

"rotation": 0,

"bitrate": 507,

"pix_format": "yuv420p",

"stream": 0.1

},

"thumb": "http://media.heywatch.com.s3.amazonaws.com/14/14/ad59fa501d1b9e826552dfc010cf1c98/11002247.jpg",

"audio": {

"sample_rate": 11025,

"channels": 1,

"codec": "aac",

"bitrate": 38,

"synched": true,

"stream": 0

},

"mime_type": "video/mp4"

},

"title": "elves.mp4",

"filename": "11002247",

"link": "http://heywatch.com/video/21091957.bin",

"updated_at": "2013-01-14T15:44:53+01:00",

"created_at": "2013-01-14T15:44:53+01:00",

"id": 21091957

}]

My Classes

public class HeyWatchVideo

{

public DateTime Created_At { get; set; }

public string Title { get; set; }

public Dictionary<string, string> Specs { get; set; }

public DateTime Updated_At { get; set; }

public int Id { get; set; }

public string Filename { get; set; }

public string Link { get; set; }

public string Url { get; set; }

}

public class HeyWatchVideoSpecs

{

public HeyWatchVideoSpecsAudio Audio { get; set; }

public HeyWatchVideoSpecsVideo Video { get; set; }

public string Thumb { get; set; }

public string Mime_type { get; set; }

public int Size { get; set; }

}

public class HeyWatchVideoSpecsVideo

{

public int Rotation { get; set; }

public double Aspect { get; set; }

public string Container { get; set; }

public string Codec { get; set; }

public int Length { get; set; }

public int Width { get; set; }

public int Bitrate { get; set; }

public string Pix_format { get; set; }

public double Fps { get; set; }

public double Stream { get; set; }

public int Height { get; set; }

}

public class HeyWatchVideoSpecsAudio

{

public int Channels { get; set; }

public int Sample_rate { get; set; }

public string Codec { get; set; }

public bool Synched { get; set; }

public int Bitrate { get; set; }

public int Stream { get; set; }

}

What am I doing wrong here?

网友答案:

My problem was solved. My .Net Classes didn't match exactly as Json object. (Both are in the question)

When they were matched, this error went away

分享给朋友:
您可能感兴趣的文章:
随机阅读: