日期:2014-05-17  浏览次数:20392 次

关于ajax 返回内容的问题
C# 部分代码:
 
  IList<UserModel> a=this.Services.GetUser1();
  IList<UserModel> b=this.Services.GetUser2();
  
  IDictionary<string,IList<UserModel>> dic=new IDictionary<UserModel>();

  dic.Add("A",a);
  dic.Add("B",b);

  return Json(dic);


js 部分代码:

  $.ajax{

   

  success:function(data){
  //在此该怎么取出返回的值呢,
  // 我是想把a,b这两个list 放到两个select控件中,该怎么做?


}


}

有没有高人阿,帮帮忙,万分感谢阿

------解决方案--------------------
public class MyJSONUtility
{
public MyJSONUtility() { }


/// <summary>
/// 封装JSON
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="obj">封装为JSON的对象</param>
/// <returns>string</returns>
public static string GetJSON<T>(object obj)
{
string result = String.Empty;
try
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, obj);
result = System.Text.Encoding.UTF8.GetString(ms.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion

  
/// <summary>
/// 把json还原为对象
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="jsonStr">json字符串</param>
/// <returns>T 对象类型</returns>
public static T ParseFormByJson<T>(string jsonStr)
{
T obj = Activator.CreateInstance<T>();
using (System.IO.MemoryStream ms =
new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonStr)))
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(ms);
}
}
------解决方案--------------------
public class MyJSONUtility
{
public MyJSONUtility() { }


/// <summary>
/// 封装JSON
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="obj">封装为JSON的对象</param>
/// <returns>string</returns>
public static string GetJSON<T>(object obj)
{
string result = String.Empty;
try
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, obj);
result = System.Text.Encoding.UTF8.GetString(ms.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
  

  
/// <summary>
/// 把json还原为对象
/// </summary>
/// <typeparam name="T&quo