Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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 从url改装调用id_Android_Retrofit - Fatal编程技术网

Android 从url改装调用id

Android 从url改装调用id,android,retrofit,Android,Retrofit,我如何在改造网络呼叫中使用这些查询并在分类结果中显示它 https://api.themoviedb.org/3/genre/{genre_id}/movies 也许这有助于: 接口类 public interface TheApiInterface{ @GET("url/bits/until/{path_variable}/then/more/url") Call<TheThingResponse> getTheThing(@Path("path_variab

我如何在改造网络呼叫中使用这些查询并在分类结果中显示它

https://api.themoviedb.org/3/genre/{genre_id}/movies

也许这有助于:

接口类

public interface TheApiInterface{
     @GET("url/bits/until/{path_variable}/then/more/url")
     Call<TheThingResponse> getTheThing(@Path("path_variable") String var);
}
您收到的JSON如下所示:

 {
"theJsonKeyOfTheFieldReturnedInServerResponse1": "the value I wanted 1",
"theJsonKeyOfTheFieldReturnedInServerResponse2": "the value I wanted 2",
"theJsonKeyOfTheFieldReturnedInServerResponse3": "the value I wanted 3",
"theJsonKeyOfTheFieldReturnedInServerResponse4": "the value I wanted 4"
 }
但您可以为更复杂的JSON构建更复杂的POJO

我发现让我的POJO都共享一个可序列化的父类是很有用的,这样可以使它们在回调中轻松移动,但是如果你想有一个更持久的存储,你也可以在这里很容易地使用ContentProvider并将一些行插入DB或类似的东西


但请记住,这都是异步的-如果您想要同步改装调用,可以使用call.execute()

我不知道您的意思-您是在问如何调用吗?谢谢您的回复。事实上,我给了错误的接口类,这就是为什么它给了我错误的原因…我如何对POST方法使用相同的东西。
public class ThingResponseCallback implements Callback<TheThingResponse>{
     @Override
     public void onResponse(Call<TheThingResponse> call, Response<TheThingResponse> response) {
        if (response.isSuccessful() && response.body() != null) {
            Log.i(TAG, "onResponse: success: theResponseFieldIWant1: " + response.theResponseFieldIWant1;);
        } else {
            Log.i(TAG, "onResponse: something went wrong with the response object " +response.body());
        }
    }

    @Override
    public void onFailure(Call<TheThingResponse> call, Throwable t) {
         Log.i(TAG, "onFailure: to: " + call.request().url() + " req " + call.request());
    }
}
public class TheThingResponse{
    @SerializedName("theJsonKeyOfTheFieldReturnedInServerResponse1")
    public String theResponseFieldIWant1;

    @SerializedName("theJsonKeyOfTheFieldReturnedInServerResponse2")
    public String theResponseFieldIWant2;

    @SerializedName("theJsonKeyOfTheFieldReturnedInServerResponse3")    
    public String theResponseFieldIWant3;

    @SerializedName("theJsonKeyOfTheFieldReturnedInServerResponse4")    
    public String theResponseFieldIWant4;
}
 {
"theJsonKeyOfTheFieldReturnedInServerResponse1": "the value I wanted 1",
"theJsonKeyOfTheFieldReturnedInServerResponse2": "the value I wanted 2",
"theJsonKeyOfTheFieldReturnedInServerResponse3": "the value I wanted 3",
"theJsonKeyOfTheFieldReturnedInServerResponse4": "the value I wanted 4"
 }