Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 改型返回LinkedTreeMap而不是JSON_Android_Json_Web Services_Gson_Retrofit - Fatal编程技术网

Android 改型返回LinkedTreeMap而不是JSON

Android 改型返回LinkedTreeMap而不是JSON,android,json,web-services,gson,retrofit,Android,Json,Web Services,Gson,Retrofit,我使用改型2.0从返回json文本的web服务读取数据,但在以下代码中,响应是LinkedTreeMap,我无法将其转换为json: 我的界面 public interface GeoAPIInterface { String ENDPOINT = "http://www.geoplugin.net/"; @GET("json.gp") Call<Object> getIP(@Query("ip") String ip); } 我建议您使用创建对象 而不是

我使用改型2.0从返回json文本的web服务读取数据,但在以下代码中,响应是LinkedTreeMap,我无法将其转换为json:

我的界面

public interface GeoAPIInterface {
    String ENDPOINT = "http://www.geoplugin.net/";

    @GET("json.gp")
    Call<Object> getIP(@Query("ip") String ip);
}
我建议您使用创建对象

而不是

Call<Object> getIP(@Query("ip") String ip);
调用getIP(@Query(“ip”)字符串ip);
你会有

Call<myObject> getIP(@Query("ip") String ip);
调用getIP(@Query(“ip”)字符串ip);

其中,
myObject
将是您的自定义对象,所有字段都在
@JSONProperty
中用适当的名称注释。这是一款非常酷且易于使用的东西。

将您的
响应
替换为
响应

public class GeoData{
    private String geoplugin_regionCode;
    private String geoplugin_city;
    private String geoplugin_credit;
    private String geoplugin_currencyConverter;
    private String geoplugin_currencyCode;
    private String geoplugin_region;
    private String geoplugin_currencySymbol;
    private String geoplugin_regionName;
    private String geoplugin_countryName;
    private String geoplugin_currencySymbol_UTF8;
    private String geoplugin_areaCode;
    private String geoplugin_dmaCode;
    private String geoplugin_continentCode;
    private String geoplugin_request;
    private String geoplugin_latitude;
    private String geoplugin_longitude;
    private String geoplugin_countryCode;
    private String geoplugin_status;

    public String getGeoplugin_regionCode () {
        return geoplugin_regionCode;
    }
    public void setGeoplugin_regionCode (String geoplugin_regionCode) {
        this.geoplugin_regionCode = geoplugin_regionCode;
    }
    public String getGeoplugin_city () {
        return geoplugin_city;
    }
    public void setGeoplugin_city (String geoplugin_city) {
        this.geoplugin_city = geoplugin_city;
    }
    public String getGeoplugin_credit () {
        return geoplugin_credit;
    }
    public void setGeoplugin_credit (String geoplugin_credit) {
        this.geoplugin_credit = geoplugin_credit;
    }
    public String getGeoplugin_currencyConverter () {
        return geoplugin_currencyConverter;
    }
    public void setGeoplugin_currencyConverter (String geoplugin_currencyConverter) {
        this.geoplugin_currencyConverter = geoplugin_currencyConverter;
    }
    public String getGeoplugin_currencyCode () {
        return geoplugin_currencyCode;
    }
    public void setGeoplugin_currencyCode (String geoplugin_currencyCode) {
        this.geoplugin_currencyCode = geoplugin_currencyCode;
    }
    public String getGeoplugin_region () {
        return geoplugin_region;
    }
    public void setGeoplugin_region (String geoplugin_region) {
        this.geoplugin_region = geoplugin_region;
    }
    public String getGeoplugin_currencySymbol () {
        return geoplugin_currencySymbol;
    }
    public void setGeoplugin_currencySymbol (String geoplugin_currencySymbol) {
        this.geoplugin_currencySymbol = geoplugin_currencySymbol;
    }
    public String getGeoplugin_regionName () {
        return geoplugin_regionName;
    }
    public void setGeoplugin_regionName (String geoplugin_regionName) {
        this.geoplugin_regionName = geoplugin_regionName;
    }
    public String getGeoplugin_countryName () {
        return geoplugin_countryName;
    }
    public void setGeoplugin_countryName (String geoplugin_countryName) {
        this.geoplugin_countryName = geoplugin_countryName;
    }
    public String getGeoplugin_currencySymbol_UTF8 () {
        return geoplugin_currencySymbol_UTF8;
    }
    public void setGeoplugin_currencySymbol_UTF8 (String geoplugin_currencySymbol_UTF8) {
        this.geoplugin_currencySymbol_UTF8 = geoplugin_currencySymbol_UTF8;
    }
    public String getGeoplugin_areaCode () {
        return geoplugin_areaCode;
    }
    public void setGeoplugin_areaCode (String geoplugin_areaCode) {
        this.geoplugin_areaCode = geoplugin_areaCode;
    }
    public String getGeoplugin_dmaCode () {
        return geoplugin_dmaCode;
    }
    public void setGeoplugin_dmaCode (String geoplugin_dmaCode) {
        this.geoplugin_dmaCode = geoplugin_dmaCode;
    }
    public String getGeoplugin_continentCode () {
        return geoplugin_continentCode;
    }
    public void setGeoplugin_continentCode (String geoplugin_continentCode) {
        this.geoplugin_continentCode = geoplugin_continentCode;
    }
    public String getGeoplugin_request () {
        return geoplugin_request;
    }
    public void setGeoplugin_request (String geoplugin_request) {
        this.geoplugin_request = geoplugin_request;
    }
    public String getGeoplugin_latitude () {
        return geoplugin_latitude;
    }
    public void setGeoplugin_latitude (String geoplugin_latitude) {
        this.geoplugin_latitude = geoplugin_latitude;
    }
    public String getGeoplugin_longitude () {
        return geoplugin_longitude;
    }
    public void setGeoplugin_longitude (String geoplugin_longitude) {
        this.geoplugin_longitude = geoplugin_longitude;
    }
    public String getGeoplugin_countryCode () {
        return geoplugin_countryCode;
    }
    public void setGeoplugin_countryCode (String geoplugin_countryCode) {
        this.geoplugin_countryCode = geoplugin_countryCode;
    }
    public String getGeoplugin_status () {
        return geoplugin_status;
    }
    public void setGeoplugin_status (String geoplugin_status) {
        this.geoplugin_status = geoplugin_status;
    }
}
这个对象中已经有了所有参数,不需要转换和解析JSON。 您可以从JSON获取对象。

您希望接收的“JSON”格式是什么?您要获取什么类型的对象?请检查
Call<myObject> getIP(@Query("ip") String ip);
public class GeoData{
    private String geoplugin_regionCode;
    private String geoplugin_city;
    private String geoplugin_credit;
    private String geoplugin_currencyConverter;
    private String geoplugin_currencyCode;
    private String geoplugin_region;
    private String geoplugin_currencySymbol;
    private String geoplugin_regionName;
    private String geoplugin_countryName;
    private String geoplugin_currencySymbol_UTF8;
    private String geoplugin_areaCode;
    private String geoplugin_dmaCode;
    private String geoplugin_continentCode;
    private String geoplugin_request;
    private String geoplugin_latitude;
    private String geoplugin_longitude;
    private String geoplugin_countryCode;
    private String geoplugin_status;

    public String getGeoplugin_regionCode () {
        return geoplugin_regionCode;
    }
    public void setGeoplugin_regionCode (String geoplugin_regionCode) {
        this.geoplugin_regionCode = geoplugin_regionCode;
    }
    public String getGeoplugin_city () {
        return geoplugin_city;
    }
    public void setGeoplugin_city (String geoplugin_city) {
        this.geoplugin_city = geoplugin_city;
    }
    public String getGeoplugin_credit () {
        return geoplugin_credit;
    }
    public void setGeoplugin_credit (String geoplugin_credit) {
        this.geoplugin_credit = geoplugin_credit;
    }
    public String getGeoplugin_currencyConverter () {
        return geoplugin_currencyConverter;
    }
    public void setGeoplugin_currencyConverter (String geoplugin_currencyConverter) {
        this.geoplugin_currencyConverter = geoplugin_currencyConverter;
    }
    public String getGeoplugin_currencyCode () {
        return geoplugin_currencyCode;
    }
    public void setGeoplugin_currencyCode (String geoplugin_currencyCode) {
        this.geoplugin_currencyCode = geoplugin_currencyCode;
    }
    public String getGeoplugin_region () {
        return geoplugin_region;
    }
    public void setGeoplugin_region (String geoplugin_region) {
        this.geoplugin_region = geoplugin_region;
    }
    public String getGeoplugin_currencySymbol () {
        return geoplugin_currencySymbol;
    }
    public void setGeoplugin_currencySymbol (String geoplugin_currencySymbol) {
        this.geoplugin_currencySymbol = geoplugin_currencySymbol;
    }
    public String getGeoplugin_regionName () {
        return geoplugin_regionName;
    }
    public void setGeoplugin_regionName (String geoplugin_regionName) {
        this.geoplugin_regionName = geoplugin_regionName;
    }
    public String getGeoplugin_countryName () {
        return geoplugin_countryName;
    }
    public void setGeoplugin_countryName (String geoplugin_countryName) {
        this.geoplugin_countryName = geoplugin_countryName;
    }
    public String getGeoplugin_currencySymbol_UTF8 () {
        return geoplugin_currencySymbol_UTF8;
    }
    public void setGeoplugin_currencySymbol_UTF8 (String geoplugin_currencySymbol_UTF8) {
        this.geoplugin_currencySymbol_UTF8 = geoplugin_currencySymbol_UTF8;
    }
    public String getGeoplugin_areaCode () {
        return geoplugin_areaCode;
    }
    public void setGeoplugin_areaCode (String geoplugin_areaCode) {
        this.geoplugin_areaCode = geoplugin_areaCode;
    }
    public String getGeoplugin_dmaCode () {
        return geoplugin_dmaCode;
    }
    public void setGeoplugin_dmaCode (String geoplugin_dmaCode) {
        this.geoplugin_dmaCode = geoplugin_dmaCode;
    }
    public String getGeoplugin_continentCode () {
        return geoplugin_continentCode;
    }
    public void setGeoplugin_continentCode (String geoplugin_continentCode) {
        this.geoplugin_continentCode = geoplugin_continentCode;
    }
    public String getGeoplugin_request () {
        return geoplugin_request;
    }
    public void setGeoplugin_request (String geoplugin_request) {
        this.geoplugin_request = geoplugin_request;
    }
    public String getGeoplugin_latitude () {
        return geoplugin_latitude;
    }
    public void setGeoplugin_latitude (String geoplugin_latitude) {
        this.geoplugin_latitude = geoplugin_latitude;
    }
    public String getGeoplugin_longitude () {
        return geoplugin_longitude;
    }
    public void setGeoplugin_longitude (String geoplugin_longitude) {
        this.geoplugin_longitude = geoplugin_longitude;
    }
    public String getGeoplugin_countryCode () {
        return geoplugin_countryCode;
    }
    public void setGeoplugin_countryCode (String geoplugin_countryCode) {
        this.geoplugin_countryCode = geoplugin_countryCode;
    }
    public String getGeoplugin_status () {
        return geoplugin_status;
    }
    public void setGeoplugin_status (String geoplugin_status) {
        this.geoplugin_status = geoplugin_status;
    }
}