加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 00:50:04 所属栏目:百科 来源:网络整理
导读:传入的对象无效,应为“:”或“}”。 如果出现了上面这个错误,应该是json格式的问题,也许是json里有url导致的吧。 解决办法: 1.客户端:发送json之前将json编码, jsonContent = encodeURIComponent(jsonContent); 而且json数据必须用双引号( 切记 )。

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

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

解决办法:

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

jsonContent = encodeURIComponent(jsonContent);

而且json数据必须用双引号( 切记)。

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);
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读