我想解析JSON結果到MVC中的DropDownList,但到目前爲止我的努力已經沒有結果。解析JSON到DropDownList
我有以下代碼:
public static SelectList getRoles(string sessionKey)
{
string URL = ConfigurationManager.AppSettings["JsonURL"].ToString();
string appName = ConfigurationManager.AppSettings["appName"].ToString();
string result = "";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(URL + "rest/" + appName + "/Role?fields=id%2Cname");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
var roles = JsonConvert.DeserializeObject<RootObject>(result);
}
我已經創建的類反序列化,但我對如何將這些數據傳遞作爲一個DropDownList到MVC視圖不知道。