ajax-json:传入的对象无效,应为“:”或“}”。

前端之家收集整理的这篇文章主要介绍了ajax-json:传入的对象无效,应为“:”或“}”。前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@传入的对象无效,应为“:”或“}”。

@H_403_0@如果出现了上面这个错误,应该是json格式的问题,也许是json里有url导致的吧。

@H_403_0@解决办法:

@H_403_0@1.客户端:发送json之前将json编码,

jsonContent = encodeURIComponent(jsonContent);

而且json数据必须用双引号( 切记)。 @H_403_0@2.WebService:

        [WebMethod]
        public static string SendEmail(string email,string jsonContent)
        {
            jsonContent = new Reports().DecodeUrl(jsonContent);//这里无法调用Server.UrlDecode,所以另写了个public方法
            return "success";
        }
        public string DecodeUrl(string s)
        {
            return Server.UrlDecode(s);
        }

猜你在找的Ajax相关文章