服务器无法解析一个有效的JSON [英] Server unable to parse a valid json

查看:418
本文介绍了服务器无法解析一个有效的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出这个Ajax请求的URL,但服务器发送一个响应无法识别的记号naejzraieale:期待'空','真','假'或NaN  在[来源:org.eclipse.jetty.server.HttpInput@13367e3;行:1,柱:25]

I am making this ajax request to a url, but server is sending a response Unrecognized token 'naejzraieale': was expecting 'null', 'true', 'false' or NaN at [Source: org.eclipse.jetty.server.HttpInput@13367e3; line: 1, column: 25].

我的Ajax请求看起来像这样

My Ajax request looks like this

$.ajax({url: "https://jsonparser.mydomain.com",
        contentType: 'application/json',
        type: "POST",
        data :{name : "juzer ali",
               email : "er.juzerali@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/passportpro",                                  "https://chrome.google.com/webstore/detail/ffimgldnoigmlcofmfkfcjechbdkipph", 
"https://github.com/juzerali", "https://docs.google.com/document/d/1BXOwXojdKwghZ3nvnfPeleEgjv0whJVWVXtQMwcXLiA/edit?pli=1", "authagentpro.appspot.com"]}
});

编辑:请注意无法识别的记号naejzraieale:。在Ĵ研究此错误字符串是从我传递的数据对象的名称属性。当我大写字母,我得到(无法识别的记号naeJZRAIeale:期待'空','真',),

Please notice Unrecognized token 'naejzraieale':. the j and r in this error string is from the name property of the object I am passing in data. When I capitalize the letters, I get (Unrecognized token 'naeJZRAIeale': was expecting 'null', 'true',)

推荐答案

将数据发送到你需要连接code就以JSON格式服务器之前, JSON.stringify和JSON.parse是由最新的浏览器提供的,但如果任何浏览器不支持,那么你可以使用一个jQuery插件做同样的 HTTP://$c$c.google.com/p/jquery-json/ ,如果​​你使用这个插件那么语法将是不同的一点点

before sending data to server you need to encode it in JSON format JSON.stringify and JSON.parse are provided by latest browsers but if any browser doesn't support that then you can use a jquery plugin to do the same http://code.google.com/p/jquery-json/, if you use this plugin then the syntax would be different a little bit

$.ajax({
       url: "https://jsonparser.mydomain.com",
       type: 'POST',
       contentType:'application/json',
       data: JSON.stringify({name : "juzer ali",
               email : "er.juzerali@gmail.com",
               how : "Used jQuery.ajax from google chromes developer console",
               urls : ["https://chrome.google.com/webstore/search/passportpro",                                  "https://chrome.google.com/webstore/detail/ffimgldnoigmlcofmfkfcjechbdkipph", 
"https://github.com/juzerali", "https://docs.google.com/document/d/1BXOwXojdKwghZ3nvnfPeleEgjv0whJVWVXtQMwcXLiA/edit?pli=1", "authagentpro.appspot.com"]}),
       dataType:'json'
});

这篇关于服务器无法解析一个有效的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆