in var data = eval ("(" + MSG.D +) ") you have to pay attention, it is easy to come out is missing}, cause is in the returned string has" "This character," "has the function of escaping all this error will occur
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: ".. /webform1.asp Tutorial X/getrightsstr ",
DataType: "JSON",
Success:function (msg) {
alert (MSG.D);
var data = eval ("+ MSG.D +"));
$.each (data.rights, function (index, item) {
alert (item.rightsname);
});
},
Error:function (E, S, D) {
Alert (e);
alert (s);
alert (d);
}
});
Background processing code
<summary>
The DataTable turns into JSON
</summary>
<param name= "Jsonname" >josn name </param>
<param name= "DT" > Data set to be converted </param>
<returns></returns>
public static string Datatabletojson (String jsonname, DataTable DT)
{
StringBuilder json = new StringBuilder ();
Json.append ("{" "+ Jsonname +" ": [");
if (Dt.rows.count > 0)
{
for (int i = 0; i < Dt.rows.count; i++)
{
Json.append ("{");
for (int j = 0; J < Dt.columns.count; J + +)
{
Json.append ("" "+ dt.columns[j].columnname.tostring () +" ":" "+ dt.rows[i][j].tostring () +" "");
if (J < dt.columns.count-1)
{
Json.append (",");
}
}
Json.append ("}");
if (I < dt.rows.count-1)
{
Json.append (",");
}
}
}
Json.append ("]}");
return json.tostring ();
}
The Eval function is evaluated as a string of numeric expressions, and its syntax is:
eval (expr)
Here expr is a string parameter that is evaluated. If the string is an expression, Eval asks for the value of the expression, and if the parameter represents one or more Web page effects statements, then Eval executes the statements. The Eval function can be used to convert a date from one format (always a string) to a numeric expression or a number