1
我正在開發一個wcf-web服務。消費者可以選擇原子響應和json響應。wcf json-response Array/List
我的OperationContract的是這樣的:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/json")]
Result GetData();
的結果類型包含了一些字符串和項的數組。
[DataContract]
public class Result
{
[DataMember]
public string baseUrl;
[DataMember]
public string url;
[DataMember]
public string title;
[DataMember]
public int totalResults;
[DataMember]
public JsonEntries[] resources;
}
我標誌着JsonEntries也爲DataContract:
[DataContract]
public class JsonEntries
{
[DataMember]
public string updated;
[DataMember]
public string key;
[DataMember]
public string title;
[DataMember]
public Salary salarie;
}
然而,當我試圖運行此我得到的錯誤,該元數據不能被調用。當我在數組前面刪除[DataMember]
時,我沒有遇到任何錯誤,但我的響應不包含數組。 我已經看到它在各種exmaples上這樣工作。那麼我做錯了什麼?
在此先感謝。
robidd
感謝幫助。我將'IsRequired = false' - 屬性添加到'DataMember'。如果我沒有這個DataMember請求Json,它給了我對象和''employee':null'。有沒有這種元素不打印的方法? – robidd 2012-07-31 15:22:59