android-改造-如何发送多值字符串列表

vxbzzdmp  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(220)

我很难把尸体送去,比如:

{
    "items": [
        "one",
        "two"
    ],
    "repositiories": [
        {
            "repo1": "aaaa",
            "repo2": "bbbb",
            "repo3": "2020-12-09T11:00:00"
        }
    ],
    "deviceName": "AndroidPhone"
}

使用改装。
我只是使用pojoschema创建了两个类,并执行了发送数据的函数:

public sentItems(List<String> items, List<Position> repositories, String deviceName) {
        this.items= items;
        this.repositories= repositories;
        this.deviceName= deviceName;
    }

我还用以下代码更新了api接口:

@POST("/api/postItems/")
    Call<SentItemsAndRepos> sentItemsAndRepos(@Body SentItemsAndRepos SentItemsAndRepos);

当我尝试发送例如静态值时,我总是得到失败语句:

onFailure: End of input at line 1 column 1 path $

只是不知道怎么打破它。。我被这个案子困住了。。也许我发送了错误的数据,但我不确定。。。我举了一个例子:

List<String> items = new ArrayList<>();
items.add("one");
items.add("two");

Repositories firstRepo = new repositories("aaaa","bbbb",Calendar.getInstance().getTime());
List<Repositories> repositories = new ArrayList<repositories>();
repositories.add(firstRepo);

String deviceName = "AndroidPhone"
postItemsFunc(items,repositories,deviceName);

private void postItemsFunc(List<String> items, List<Position> repositories, String deviceName){

            SentItemsAndRepos sentItemsAndRepos= new SentItemsAndRepos(items,repositories,deviceName);
            Call<SentItemsAndRepos> call = ApiLoginInterface.sentItemsAndRepos(sentItemsAndRepos);
            call.enqueue(new Callback<SentItemsAndRepos>() {

这是我认为你想帮助的任何东西,如果你想帮助的话,ofc:)我将非常感谢你的时间来帮助我。。。

lhcgjxsq

lhcgjxsq1#

我正在从git存储库中实现一些源代码

public void fetchContact(String type, String key){

    apiInterface = ApiClient.getApiClient().create(ApiInterface.class);

    Call<List<Contact>> call = apiInterface.getContact(type, key);
    call.enqueue(new Callback<List<Contact>>() {
        @Override
        public void onResponse(Call<List<Contact>> call, Response<List<Contact>> response) {
            progressBar.setVisibility(View.GONE);
            contacts = response.body();
            adapter = new Adapter(contacts, MainActivity.this);
            recyclerView.setAdapter(adapter);
    //        adapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure(Call<List<Contact>> call, Throwable t) {
            progressBar.setVisibility(View.GONE);
            Toast.makeText(MainActivity.this, "Error\n"+t.toString(), Toast.LENGTH_LONG).show();
        }
    });
}

请访问以下链接以轻松理解 https://github.com/Istiakshovon/RetrofitRecyclerView/blob/master/app/src/main/java/com/istiak/getdatabyretrofit/MainActivity.java

相关问题