C#: Code
///
/// List转换Jsion 数据
///
///
///
///
///
public static string ObjectToJson(IList IL)
{
StringBuilder Json = new StringBuilder();
Json.Append("[");
if (IL.Count > 0)
{
for (int i = 0; i < IL.Count; i++)
{
T obj = Activator.CreateInstance();
Type type = obj.GetType();
System.Reflection.PropertyInfo[] pis = type.GetProperties();
Json.Append("{");
for (int j = 0; j < pis.Length; j++)
{
Json.Append("\"" + pis[j].Name.ToString() + "\":\"" + pis[j].GetValue(IL[i], null) + "\"");
if (j < pis.Length - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < IL.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]");
return Json.ToString();
}
JS:Code
$.ajax({
type: "get",
url: "UserMethod.ashx",
cache: false,
data: "MID=GetCity&ProId="+id,
dataType: 'text',
success: function(data){
var j = eval(data)
var subSel=$("#sel_city");
subSel.prepend("请选择");
$.each(j,function( i,value){
var subOp = $("");
subOp.attr("id",'ocity_' + value.Id);
subOp.attr("value",value.Id);
subOp.html(value.Name);
subSel.attr("onchange",'javascript:checkCityValue();');
subSel.append(subOp)
isTrue=false;
});
},
error: function(){
return;
}
});