这是我的代码。我遇到的问题是代码jsonVersionList[0]
得到了一个字符串“[”,实际上我想解析jsonVersionList
为 Json 对象,我认为原因是 JavaScript 将jsonVersionList
其视为字符串而不是 Json 对象。请帮助我。谢谢。
function ajaxGetSystemTraceLog(jsonRequest) {
var sUrl = "/api/SysTraceLog";
$.ajax({
cache: false,
type: "POST",
async: false,
url: sUrl,
data: jsonRequest,
contentType: "application/json",
dataType: "json",
success: function (result) {
var sHtml = buildLogDiv(JSON.stringify(eval(result)));
$("#effect").html(sHtml);
showCenter("#effect", false, 0, 0);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
}
function buildLogDiv(jsonVersionList) {
var sHtml = "<table style=\"width:100%;\"><tr><td style=\"width:100%;background-color:#005CE6;\" align=\"right\"><img onclick=\"hide('#effect', false);\" alt=\"close it\" title=\"close it\" src=\"/content/themes/default/images/cancel.png\" width=\"20\" height=\"20\" /></td></tr>";
sHtml += "<tr><td style='text-align:left'>";
sHtml += jsonVersionList[0];
sHtml += "</td></tr></table>";
return sHtml;
}
public class SysTraceLogController : ApiController
{
public string Post(QueryTraceLogRequestModel queryTraceLogReq)
{
return "[\"1\",\"2\",\"3\",\"4\"]";
}
}