我正在使用 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);
}
现在我从网站读取数据:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(GeoAPIInterface.ENDPOINT)
.addConverterFactory(GsonConverterFactory.create())
.build();
GeoAPIInterface inBankAPI = retrofit.create(GeoAPIInterface.class);
Call<Object> call=inBankAPI.getIP("8.8.8.8");
call.enqueue(new Callback<Object>() {
@Override
public void onResponse(Response<Object> response, Retrofit retrofit) {
Log.d("App","");
}
@Override
public void onFailure(Throwable t) {
Log.d("App","error!");
}
});
形成的网址是http://www.geoplugin.net/json.gp?ip=8.8.8.8
json 响应是
{
"geoplugin_request":"8.8.8.8",
"geoplugin_status":200,
"geoplugin_credit":"Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\\'http:\/\/www.maxmind.com\\'>http:\/\/www.maxmind.com<\/a>.",
"geoplugin_city":"Mountain View",
"geoplugin_region":"CA",
"geoplugin_areaCode":"650",
"geoplugin_dmaCode":"807",
"geoplugin_countryCode":"US",
"geoplugin_countryName":"United States",
"geoplugin_continentCode":"NA",
"geoplugin_latitude":"37.386002",
"geoplugin_longitude":"-122.083801",
"geoplugin_regionCode":"CA",
"geoplugin_regionName":"California",
"geoplugin_currencyCode":"USD",
"geoplugin_currencySymbol":"$",
"geoplugin_currencySymbol_UTF8":"$",
"geoplugin_currencyConverter":1
}