[英]SyntaxError: missing ; before statement in JSON
I am getting a very strange error while the response is correct and I can see the JSON content: 我得到一个非常奇怪的错误,而响应是正确的,我可以看到JSON内容:
here is the request: 这是请求:
$.ajax({
type: "GET",
url: urlTwitter,
contentType: "application/json",
dataType: "jsonp",
async: false,
success: function (resp, status, xhr) {
$("#message").html("STATUS: " + xhr.status + " " + xhr.statusText + "\n" + resp);
$("#message").hide();
$.each(resp, function() {
$.each(this, function(i, tweet) {
arrayTweets.push(tweet);
});
});
displayTweets();
},
error: function(resp, status, xhr){
$("#message").html("ERROR: " + xhr.status + " " + xhr.statusText + "\n" + resp.e);
$("#message").show();
}
});
Here is the conent in the response: 以下是响应中的内容:
{"tweet":[{"text":"RT @OSCARHAROTASEND: MUYYY CONTENTO Y MUYYY ORGULLOSO del trabajo d mi hermanito @pablonieto22 en la presentación d su TEAM @CalvoTeam anoc…","user":"Jemurillove"}]}
Anyone has a clue, I've been fighting with this half day. 任何人都有线索,我一直在与这半天战斗。
Appreciate any help. 感谢任何帮助。
Thanks, 谢谢,
EDIT: 编辑:
this is my resource, if it can help. 这是我的资源,如果它可以帮助。 And the Tweet object is annotated with
@XmlRootElement
: Tweet对象使用
@XmlRootElement
注释:
@GET
@XmlElement(name = "tweet")
@Path("/retrieveTweets")
@Produces(MediaType.APPLICATION_JSON)
public List<Tweet> retrieve(@QueryParam("lat") Double Latitude, @QueryParam("lon") Double Longitude, @QueryParam("rad") Double Radius, @QueryParam("from") String From, @QueryParam("to") String To) {
//List<Status> tweets = null;
List<Tweet> lTweets = new ArrayList<Tweet>();
boolean status = false;
Twitter twitter = new TwitterFactory().getInstance();
AccessToken accessToken = new AccessToken(TwitterInterface.ACCESS_TOKEN, TwitterInterface.ACCESS_TOKEN_SECRET);
twitter.setOAuthConsumer(TwitterInterface.CONSUMER_KEY, TwitterInterface.CONSUMER_SECRET);
twitter.setOAuthAccessToken(accessToken);
try {
Query query = new Query("");
GeoLocation geo = new GeoLocation(Latitude, Longitude);
query.setGeoCode(geo, Radius/1000, Query.KILOMETERS);
query.setCount(100);
query.setSince(From);
query.setUntil(To);
QueryResult result;
result = twitter.search(query);
List<Status>tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
Tweet t = new Tweet();
t.setUser(tweet.getUser().getScreenName());
t.setText(tweet.getText());
lTweets.add(t);
}
}
catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
return lTweets;
You are requesting a jsonp
response, but the response is plain JSON. 您正在请求
jsonp
响应,但响应是纯JSON。
You can either change the request type to 'JSON' - if the request doesn't fall foul of cross-domain restrictions, or change whatever is generating the response to wrap the response as JSONP. 您可以将请求类型更改为“JSON” - 如果请求不会违反跨域限制,或者更改生成响应的任何内容以将响应包装为JSONP。
For more information on JSONP, have a look at the jQuery docs 有关JSONP的更多信息,请查看jQuery文档
In summary, jQuery automatically adds a callback=?
总之,jQuery自动添加一个
callback=?
parameter to the url it requests. 它请求的url的参数。 Your server-side code needs to use the value of that parameter as the name of a javascript function your response should invoke with the JSON passed as an argument.
您的服务器端代码需要使用该参数的值作为您的响应应该使用作为参数传递的JSON调用的javascript函数的名称。
For example, if callback=helloWorld
, your response should be: 例如,如果
callback=helloWorld
,您的响应应该是:
helloWorld({"tweet": ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.