2011-06-23 62 views
0

我在我的jQuery代碼中創建一個數組,然後調用stringify使其成爲json數據,然後調用一個服務接收一個對象,但不幸的是我得到這個錯誤,並且這個錯誤是由於我的對象由數組屬性組成,我有相同的代碼,並且當我的對象只有字符串和數字時它們都工作正常。這是我的對象格式化程序在嘗試反序列化消息時拋出一個異常:嘗試反序列化參數時發生錯誤

[Serializable] 
[DataContract] 
public class ImagesEditInfo 
{ 

    [DataMember(IsRequired=true)] 
    public int[] ImageIds 
    { 
     get; 
     set; 
    } 

}

誰能幫助請的一部分嗎?

回答

0

你的服務是什麼樣子,你可以提供一些示例請求?

我大約用在你的情況下,這對於服務調用

$.ajax({ 
     type: 'POST', 
     url: serviceURL, 
     contentType: 'application/json', 
     data: JSON.stringify({ serviceParameterName: javascriptObject }), 
     success: successFunction, 
     dataType: 'json' 
    }); 

您的服務方法就必須是這樣的:

[OperationContract] 
    [WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = serviceURL, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 
    public string methodName(ImagesEditInfo serviceParameterName) { } 
+0

當然,是這樣的。 – user510336

+0

[OperationContract的] [WebInvoke(ResponseFormat = WebMessageFormat.Json,方法= 「POST」,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate = 「ImagesEdit」)] 公共字符串UpdateImages(ImagesEditInfo ImagesInfo) { } $就({ 網址: 「服務URL」, 數據類型: 'JSON' 類型: '後', 過程數據:假的, 的contentType: '應用/ JSON', 數據: '數據後', - 這是字符串化對象 成功:function(){ //成功執行任何操作 return; }, – user510336

+0

這是我如何創建對象 var serviceData = {ImageIds:imageids,ImageNames:imagenames,ImageDescriptions:imagedescriptions,imagetags:ImageTags,IsDownloadable:isdownloadables,IsCommentable:iscommentables}; serviceData = {ImagesInfo:serviceData}; – user510336

相關問題