gpt4 book ai didi

android - 没有通过 REST 调用接收 json 数据

转载 作者:行者123 更新时间:2023-12-03 23:07:01 25 4
gpt4 key购买 nike

我正在尝试使用改造来使用我自己的 REST 调用。我关于它为什么不起作用的唯一线索是它说信息的类型是“text/html”,即使我确定它是 json。话虽如此,我还没有找到任何解决我问题的答案。

有效载荷:

  [
{
"user_id": "32",
"username": "Marko",
"last_activity": "2020-04-26 20:44:00",
"user_image": "slika2"
},
{
"user_id": "33",
"username": "dejan",
"last_activity": "2020-04-26 20:44:00",
"user_image": "slika3"
}
]

我的聊天课:
public class Chat {

@SerializedName("user_id")
private String userId;

private String username;

@SerializedName("last_activity")
private String lastActivity;

@SerializedName("user_image")
private String userImage;\

...constructor/getters

}

API接口(interface):
@FormUrlEncoded
@POST("api_get_all_chats.php")
Call<List<Chat>> getChats(
@Field("id") String id
);

API客户端:
public static Retrofit getClient() {

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.level(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl("http://MYIP/emob%20projekat/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
return retrofit;
}

整个请求:
        apiInterface = ApiClient.getClient().create(userApi.class);

Call<List<Chat>> call = apiInterface.getChats(u.getUserInfo().getUserId());

call.enqueue(new Callback<List<Chat>>() {
@Override
public void onResponse(Call<List<Chat>> call, Response<List<Chat>> response) {
chatList = new ArrayList<>(response.body());
chatAdapter = new ChatAdapter(getApplication().getApplicationContext(), R.layout.user_view, chatList);
listView.setAdapter(chatAdapter);
}

@Override
public void onFailure(Call<List<Chat>> call, Throwable t) {
Toast.makeText(getApplication().getApplicationContext(), "ne valja" , Toast.LENGTH_LONG).show();

}
});

任何我搞砸的线索都将不胜感激。

最佳答案

当我解码时你的基本网址有空间我得到了

http://MYIP/emob projekat/api/

我建议您放置不编码的基本 URL

关于android - 没有通过 REST 调用接收 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61889997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com