2011-10-13 66 views
0

我得到在POST請求JSON對象(即NewDataSet),見下文(螢火蟲要求對象)圖像JSON對象...無法讀取POST請求「ASP.net」

enter image description here

我怎樣才能得到這個對象在服務器端?

感謝上JSON.net

+0

我認爲它已經在這裏得到解答:http://stackoverflow.com/questions/4367022/working-with-json-on-the-server-side-in-asp-net-and-c – Prashant

回答

0

結賬信息,我將創建一個服務器端對象匹配您正在發佈到服務器的JSON對象。

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

在你的web服務,你可以設置服務的定義是這樣的:

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

你需要告訴您正在發送json的客戶端發佈腳本:

contentType: 'application/json' 

如果我請記住,這將告訴ASP.NET將您的JSON對象反序列化爲.NET類。