我試圖簡化從我的WebMethod層返回數據到客戶端的過程,並代表來自客戶端的一組參數Dictionary<string,string>
做某事像這樣:調用一個傳遞Dictionary <string,string>作爲參數的WebMethod
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static override ResultObject<List<PatientInfo>> GetResults(Dictionary<string, string> query)
{
ResultObject<List<PatientInfo>> resultObject = null;
if (!query.ContainsKey("finValue"))
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter from the query");
}
string finValue = query["finValue"];
if(finValue == null)
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter value from the query");
}
var patientData = GetPatientsByFin(finValue);
resultObject = new ResultObject<List<PatientInfo>>(patientData);
return resultObject;
}
}
我的問題是:如何傳遞和反序列化Dictionary參數?
最重要的這裏的事情是,在JSON字符串屬性的Web方法參數名稱相匹配,在這種情況下,「值」。 – Matt