传入json字符串格式问题,请高手赐教
aspx页面中的脚本如下:
function selectAll() {
var table;
$.ajax({
url: "1.ashx",
type: "post",
dataType: "json",
data: { action: "all" },
async:false ,
success: function (data) {
if (data) {
table = eval("("+data +")");
}
}
});
alert(table .Rows.length);
}
1.ashx的部分代码如下:
context.Response.ContentType = "text/plain";
StringBuilder jsonStr = new StringBuilder();
DataTable table = new SqlHelper().GetTable("select Name,Age,Job,Introduc from dbo.Member");
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
string m = "{" + string.Format("name:'{0}',age:'{1}',job:'{2}',Introduc:'{3}'", row[0], row[1], row[2], row[3]) + "}";
jsonStr.Append(m);
}
string finalJson = "{" + string.Format("Name:'table',Rows:'{0}'","["+ jsonStr.ToString()+"]") + "}";
context.Response.Write(finalJson);
这个json字符串格式的字符串finalJson 传不会页面是如何回事啊?
另外在文本可视化工具中看到finalJson这个变量的值就是
{Name:'table',Rows:'[{name:'啦啦',age:'21',job:'软件开发',Introduc:'我一定会越来越强的'}{name:'haha',age:'21',job:'软件测试',Introduc:'我一定会越来越强的'}{name:'嘻