我必须拨打电话,使用改装1.9将json发送到api,该电话我将在Json中收到天气信息的回复。 为了实现它,我已经遵循了这个stackoverflow question
这是我发送的json:
{jsondata:{" when":1," city":2}}
这是我的界面:
public interface ApiCalls {
@POST("/getConditions.php")
void getConditions(@Body JsonAdded json, Callback <List<PojoBeaches>> response);
}
我为(@body JsonAdded json,..)参数创建的类</ p>
> public class Jsondata {
@SerializedName("when")
@Expose
private Integer when;
@SerializedName("city")
@Expose
private Integer city;
public Integer getWhen() {
return when;
}
public void setWhen(Integer when) {
this.when = when;
}
public Integer getCity() {
return city;
}
public void setCity(Integer city) {
this.city = city;
}
}
和
public class JsonAdded {
@SerializedName("jsondata")
@Expose
private Jsondata jsondata;
public Jsondata getJsondata() {
return jsondata;
}
public void setJsondata(Jsondata jsondata) {
this.jsondata = jsondata;
}
}
最后是电话和回调
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Constants.GET_API_URL_BASE)
.build();
apiGet = adapter.create(ApiCalls.class);
Jsondata jsondata = new Jsondata();
jsondata.setCity(1);
jsondata.setWhen(1);
JsonAdded jsonAdded = newJsonAdded();
jsonAdded.setJsondata(jsondata);
apiGet.getConditions(jsonAdded, new Callback <List<PojoBeaches>>() {
@Override
public void success(List<PojoBeaches> pojoBeaches, Response response) {
Log.d(Constants.TAG,"SUCESS ");
}
@Override
public void failure(RetrofitError error) {
Log.d(Constants.TAG,"ERROR "+error.getMessage());
}
});
我的问题是我得到null作为错误,我一直在实现其他解决方案,但没有任何工作,总是null得到。
我得到的Log猫只是&#34; ERROR null&#34; 。
有什么想法吗?请问我做错了什么?
已修改并添加了setLogLevel(RestAdapter.LogLevel.FULL)
D / Retrofit:java.io.EOFException 在libcore.io.Streams.readAsciiLine(Streams.java:203) 在libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560) 在libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813) 在libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486) at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73) at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38) at retrofit.RestAdapter $ RestHandler.invokeRequest(RestAdapter.java:326) at retrofit.RestAdapter $ RestHandler.access $ 100(RestAdapter.java:220) at retrofit.RestAdapter $ RestHandler $ 2.obtainResponse(RestAdapter.java:278) at retrofit.CallbackRunnable.run(CallbackRunnable.java:42) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:569) at retrofit.Platform $ Android $ 2 $ 1.run(Platform.java:142) 在java.lang.Thread.run(Thread.java:856)