开发者

Unable to read JSON object from POST request "ASP.net"

开发者 https://www.devze.com 2023-04-12 12:20 出处:网络
I\'m getting a JSON objec开发者_如何学编程t(i.e. NewDataSet) in the POST request, see image below (Firebug-request object)...

I'm getting a JSON objec开发者_如何学编程t(i.e. NewDataSet) in the POST request, see image below (Firebug-request object)...

Unable to read JSON object from POST request "ASP.net"

How can i get this object at server side ??

Thanks Xtremist


I would create a server side object matching the JSON object you are posting to the server.

public class DataPackage
{
    public string CostType {get; set;}
    public string CostName {get; set;}
    public bool isEditable {get; set;}
    ...
}

In your webservice you can setup the service definition like this:

[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json, XmlSerializeString = false)]
public void MyWebservice(DataPackage NewDataSet) {
    ...
}

You need to tell your client side posting script that you are sending json:

contentType: 'application/json'

If I remember correctly this will tell ASP.NET to deserialize your JSON object into the .NET class.


Checkout information on JSON.net

0

精彩评论

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

关注公众号