Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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
java.lang.IllegalStateException:Expectet是一个字符串,但在第1行第16列路径$[0]处是BEGIN_数组。问题_Java_Android_Gson_Retrofit - Fatal编程技术网

java.lang.IllegalStateException:Expectet是一个字符串,但在第1行第16列路径$[0]处是BEGIN_数组。问题

java.lang.IllegalStateException:Expectet是一个字符串,但在第1行第16列路径$[0]处是BEGIN_数组。问题,java,android,gson,retrofit,Java,Android,Gson,Retrofit,我查看了一些关于这个主题的其他线程,并集成了它提供的解决方案,但它仍然抛出相同的错误。这是我第一次尝试在android上调用api。这里我想“获取”一个对象数组。由于应用程序未崩溃,因此没有堆栈跟踪。我认为问题与一系列问题有关 Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://192.168.1.100:3000/api/")

我查看了一些关于这个主题的其他线程,并集成了它提供的解决方案,但它仍然抛出相同的错误。这是我第一次尝试在android上调用api。这里我想“获取”一个对象数组。由于应用程序未崩溃,因此没有堆栈跟踪。我认为问题与一系列问题有关

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.1.100:3000/api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
        Call<List<Post>> call = jsonPlaceHolderApi.getPosts();
        call.enqueue(new Callback<List<Post>>() {
            @Override
            public void onResponse(Call<List<Post>> call, Response<List<Post>> response) {
                if (!response.isSuccessful()){
                    textViewResult.setText("Code: " + response.code());
                    return;
                }

                List<Post> posts = response.body();

                for (Post post : posts){
                    String content = "";
                    content += "Doctor: " + post.getDoctor() + "\n";
                    content += "Name: " + post.getName() + "\n";
                    content += "Questions: " + post.getQuestions() + "\n\n";

                    textViewResult.append(content);
                }
            }

            @Override
            public void onFailure(Call<List<Post>> call, Throwable t) {
                textViewResult.setText(t.getMessage());
            }
        });

我修好了。问题是我的模型中的'questions'属性的类型是string,而不是List string

package com.example.medlog;

import java.util.List;

public class Post {
    private String name;
    private String doctor;
    private List<String> questions;

    public String getName() {
        return name;
    }

    public String getDoctor() {
        return doctor;
    }

    public List<String> getQuestions() {
        return questions;
    }
}
package com.example.medlog;
导入java.util.List;
公营职位{
私有字符串名称;
私家医生;
私人名单问题;
公共字符串getName(){
返回名称;
}
公共字符串getDoctor(){
返回医生;
}
公共列表问题(){
回答问题;
}
}

请发布完整堆栈跟踪。请回答问题并使用json数据和完整堆栈跟踪更新。
package com.example.medlog;

import java.util.List;

public class Post {
    private String name;
    private String doctor;
    private List<String> questions;

    public String getName() {
        return name;
    }

    public String getDoctor() {
        return doctor;
    }

    public List<String> getQuestions() {
        return questions;
    }
}