最好是这种格式输出来的。 Response.Write(JsonConvert.SerializeObject(“a")),还有我用的是vs2008 要下载那个版的Newtonsoft.Json.dll 才可以。我还没有Newtonsoft.Json.dll的最新版。
这里不是说的很清楚了吗?
http://space.cnblogs.com/q/15470/
个人建议使用 jQuery json
public static string ToJson(this object obj){
return ToJson(obj, null);
}
public static string ToJson(this object obj, IEnumerable<JavaScriptConverter> jsonConverters) {
JavaScriptSerializer serializer = new JavaScriptSerializer();
if (jsonConverters != null) serializer.RegisterConverters(jsonConverters ?? new JavaScriptConverter[0]);
return serializer.Serialize(obj);
}
using System.Web.Script.Serialization;
引用:System.Runtime.Serialization
$.ajax({
type: "get",
url: "../Ajax/assessHandler.ashx",
dataType: "text",
data: "cmd=GetDocumentsList",
beforeSend: function(XMLHttpRequest) {
//
},
success: function(json) {
var Arr = eval(json);
for (var i = 0; i < Arr.length; i++) {
alert(Arr[i]["assessmenttext"]);
return;
}
},
complete: function(XMLHttpRequest, textStatus) {
},
error: function() {
alert("加载出错")
}
});
var GetDocumetsList = function() {
$.getJSON("../ajax/assessHandler.ashx?cmd=GetDocumentsList", function(data) {
var str = "";
$.each(data, function(i, item) {
var assessmentid = data[i].assessmentid;
var assessmenttext = data[i].assessmenttext;
var attributes = data[i].attributes;
str += "<option value='" + assessmentid + "' attributes='" + attributes + "'>" + assessmenttext + "</option>";
});
$(str).appendTo("#select_documenttype");
});
}