fi.foyt.foursquare.api.FoursquareApiException: org.json.JSONException: JSONObject[ "icon" ] 不是字符串



我从git中获取了foursquare示例java代码和相同的示例值,并在本地机器中运行,但出现了以下异常。这是我的代码:

String ll = args.length > 0 ? args[0] : "44.3,37.2";
    try {
        FourSquareSampleMain fourSquareSample = new FourSquareSampleMain();
        fourSquareSample.searchVenues(ll);
    } catch (FoursquareApiException e) {
        // TODO: Error handling
        e.printStackTrace();
    }
}
public void searchVenues(String ll) throws FoursquareApiException {
    // First we need a initialize FoursquareApi.
    FoursquareApi foursquareApi = new FoursquareApi("CLIENT_ID",
            "CLIENT_SECRET", null);
    // After client has been initialized we can make queries.
    Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null,
            null, null, null, null, null);
    if (result.getMeta().getCode() == 200) {

        CompactVenue[] venueList = result.getResult().getVenues();
        System.out.println("Compact Venue List size : " + venueList.length);
        // if query was ok we can finally we do something with the data
        for (CompactVenue venue : venueList) {
            // TODO: Do something we the data
            System.out.println("Venue Name : " + venue.getName());
        }
        System.out.println("End of IF Loop: ");
    } else {
        // TODO: Proper error handling
        System.out.println("Error occured: ");
        System.out.println("  code: " + result.getMeta().getCode());
        System.out.println("  type: " + result.getMeta().getErrorType());
        System.out.println("  detail: " + result.getMeta().getErrorDetail());
    }
}

venueList的大小总是"0",但当我调试它时,它抛出以下异常:

"org.eclipse.debug.core.DebugException:com.sun.jdi.ClassNotLoadedException:检索数组的组件类型时发生未加载类型。"

但奇怪的是,当我更改经纬度值时,

String ll = "-33.883056 , 151.216667";// latlong surry hills sydney

我得到以下异常:

fi.foyt.foursquare.api.FoursquareApiException:org.json.JSONException:JSONObject["icon"]不是字符串。位于fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:143)位于fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldParser.java:194)位于fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldParser.java:141)位于fi.foyt.foursquare.api.JSONFieldParser.parseEntities(JSONFieldParser.java:57)在fi.foyt.foursquare.api.ForsquareApi.venuesSearch(FoursquareApi.java:1017)在FourSquareSampleMain.searchVenues(FourSquareSampleMain.java:57)位于FourSquareSampleMain.main(FourSquareSampleMain.java:43)由:org.json.JSONException引起:JSONObject["icon"]不是字符串。位于org.json.JSONObject.getString(JSONObject.java:658)在fi.foyt.foursquare.api.JSONFieldParser.parseValue(JSONFieldPather.java:202)在fi.foyt.foursquare.api.JSONFieldParser.parseEntity(JSONFieldPather.java:141)

我在这里错过了什么?请提出建议。

我找到了一个解决方法。这是一个补丁,但它有效。详细信息:

  1. 信息取自该帖子,其中发现并解决了相同的问题
  2. 看看解决问题的差异:https://github.com/wallabyfinancial/foursquare-api-java/compare/master...ganchix:master
  3. 照原样复制这3个原始类(Category、GeoCodeFeature和Icon),并将它们添加到包fi.foyt.foursquare.api.entities下的porject中,就这样了

注意1:当您在yur项目中替换类(相同的包和类名)时,claslider将使用您的类,而不是jar依赖项提供的类,因此,有一个快速解决方案。我做到了,它就像一个魅力

注意2:sdk更新后,您应该立即删除此补丁并升级sdk依赖

希望它能帮助

最新更新