$.parseJSON(data)只支持标准的JSON

前端之家收集整理的这篇文章主要介绍了$.parseJSON(data)只支持标准的JSON前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

$.parseJSON()只支持标准的JSON,不标准的还是用eval("("+data+")")吧

什么 是标准的呢?

key和value都带引号的就是标准的; 而且必须是双引号,单引号也不行

understand?


举例:

string msg = "";
Model.Users currentUser;
string jsonStr = "";
//JavaScriptSerializer js = new JavaScriptSerializer();
bool result = bll.UserLogin(loginID,loginPwd,out msg,out currentUser);
if (!result)
{
jsonStr = "{\"result\":\"false\",\"msg\":\"" + msg + "\"}"; context.Response.Write(jsonStr); } else { //记录登陆成功的用户到Session中 context.Session.Add("currUser",currentUser); if (string.IsNullOrEmpty(redirectUrl)) { jsonStr = "{\"result\":\"true\",\"msg\":\"OK\",\"redirect\":\"\"}"; context.Response.Write(jsonStr); } else { jsonStr = "{\"result\":\"true\",\"redirect':\"" + context.Server.UrlDecode(redirectUrl) + "\"}"; context.Response.Write(jsonStr); } }

原文链接:https://www.f2er.com/json/289516.html

猜你在找的Json相关文章