开发者

Json.NET - JsonConvert.DeserializeObject isn't doing anything

I'm using Json.NET to deserialize a jQuery.post() JSON param.

The raw value that's posted back is in the following format

jobs=4-5-6-7&invoiceDate=04-05-11

The class I'm trying to deserialize into is

public class InvoiceRequest
{
    public DateTime InvoiceDate { get; set; }
    public string JobList { get; set; }
}

And the code I'm using for this is

var sr = new System.IO.StreamReader(Request.InputStream);
var line = sr.ReadToEnd();
var deserializedProduct = JsonConvert.DeserializeObject<InvoiceRequest>(line);

The problem is that nothing happens when that third line is hi开发者_高级运维t. When I step through the code, it reaches that line and then... nothing. The stepper disppears and the page never receives any response.

Can anyone explain what I'm doing wrong here?


The following is application/x-www-form-urlencoded request, not JSON:

jobs=4-5-6-7&invoiceDate=04-05-11

If you want JSON the request should look like this:

{ 'jobs': '4-5-6-7', invoiceDate: '04-05-11' }


It's not working because your data isn't JSON. Either change your JavaScript so that it sends data as JSON, or use HttpUtility.ParseQueryString to parse the format it's currently in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜