在Google Cloud Endpoints上运行的Foursquare API Java上发生错误JSON解析请求

时间:2022-09-07 10:15:52

I used the code [1] and I've implemented in Google Cloud Endpoints (since I can't use org.json I copied the code [2]), but I've an error when parse the request gives me a JSON exception of the ["icon"] field.

我使用了代码[1]并且我在Google Cloud Endpoints中实现了(因为我无法使用org.json我复制了代码[2]),但是在解析请求时我遇到了一个错误,给了我一个JSON异常[“icon”]字段。

[1] https://code.google.com/p/foursquare-api-java/ [2] https://github.com/douglascrockford/JSON-java

[1] https://code.google.com/p/foursquare-api-java/ [2] https://github.com/douglascrockford/JSON-java

Here is my code:

这是我的代码:

@ApiMethod(name = "searchVenues")
public List<Api> searchVenues(@Named("ll")String ll) throws FoursquareApiException, CiudadAppoyoApiException {


    //ll="6.5589393,-73.1290595";

    List<Api> venuesList = new ArrayList<Api>();

    // First we need a initialize FoursquareApi.
        FoursquareApi foursquareApi = new FoursquareApi("Client ID", "Client Secret", "Callback URL");
        Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null, null, null, null, null, null);

        if (result.getMeta().getCode() == 200) {

            // if query was ok we can finally we do something with the data

            for (CompactVenue venue : result.getResult().getVenues()){
                Api venuesObj = new Api();
                System.out.println(venue.getName());
                venuesObj.setVenue(venue);
                venuesObj.setFoursquareId(Long.getLong(venue.getId()));
                venuesList.add(venuesObj);
            }

            return venuesList;
        } else {
            if (result.getMeta().getCode() == 400) throw new CiudadAppoyoApiException("Request no valido");
            if (result.getMeta().getCode() == 404) throw new CiudadAppoyoApiException("Ningún resultado");
            if (result.getMeta().getCode() == 500) throw new CiudadAppoyoApiException("Error en el servidor");
            return venuesList;
        }

}

Here are the logs

这是日志

Jan 13, 2015 8:55:34 AM com.google.api.server.spi.SystemServiceServlet init
INFO: SPI restricted: true
Jan 13, 2015 8:55:37 AM com.google.api.server.spi.SystemService invokeServiceMethod
INFO: cause={0}
fi.foyt.foursquare.api.FoursquareApiException: org.json.JSONException: JSONObject["icon"] not a string.
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:140)
  at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:191)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:138)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntities(JSONFieldParser.java:57)
  at fi.foyt.foursquare.api.FoursquareApi.venuesSearch(FoursquareApi.java:939)
  at com.jiacp.ciudadappoyo.backend.foursquare.apiEndpoint.searchVenues(apiEndpoint.java:87)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
  at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
  at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
  at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:326)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
  at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
  at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.json.JSONException: JSONObject["icon"] not a string.
  at org.json.JSONObject.getString(JSONObject.java:664)
  at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:199)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:138)
  ... 49 more

Jan 13, 2015 8:55:37 AM com.google.api.server.spi.SystemService invokeServiceMethod
SEVERE: org.json.JSONException: JSONObject["icon"] not a string.
fi.foyt.foursquare.api.FoursquareApiException: org.json.JSONException: JSONObject["icon"] not a string.
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:140)
  at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:191)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:138)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntities(JSONFieldParser.java:57)
  at fi.foyt.foursquare.api.FoursquareApi.venuesSearch(FoursquareApi.java:939)
  at com.jiacp.ciudadappoyo.backend.foursquare.apiEndpoint.searchVenues(apiEndpoint.java:87)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:483)
  at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
  at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
  at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
  at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
  at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:326)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
  at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
  at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.json.JSONException: JSONObject["icon"] not a string.
  at org.json.JSONObject.getString(JSONObject.java:664)
  at fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:199)
  at fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:138)
  ... 49 more

1 个解决方案

#1


0  

Looking at the Foursquare API doco 'icon' isn't listed as a return value.

查看Foursquare API doco'icon'未列为返回值。

I use the same Java Foursquare API and had to check it out and make a lot of changes to it to enable it to be valid with the current spec.

我使用相同的Java Foursquare API并且必须检查它并对其进行大量更改以使其对当前规范有效。

My suggestion is to take a look at the VenuesSearchResult class and see if there is a reference to icon in there.

我的建议是看看VenuesSearchResult类,看看那里是否有对图标的引用。

#1


0  

Looking at the Foursquare API doco 'icon' isn't listed as a return value.

查看Foursquare API doco'icon'未列为返回值。

I use the same Java Foursquare API and had to check it out and make a lot of changes to it to enable it to be valid with the current spec.

我使用相同的Java Foursquare API并且必须检查它并对其进行大量更改以使其对当前规范有效。

My suggestion is to take a look at the VenuesSearchResult class and see if there is a reference to icon in there.

我的建议是看看VenuesSearchResult类,看看那里是否有对图标的引用。