Java 当试图通过改型上传图像时,如何解析JSON文档未完全使用

Java 当试图通过改型上传图像时,如何解析JSON文档未完全使用,java,android,retrofit,image-uploading,Java,Android,Retrofit,Image Uploading,我写了一个rest调用,使用改型将图像上传到服务器。我想我已经在这里遵循了一些步骤 但我无法从这些步骤中得到任何积极的结果 我一直收到“com.google.gson.JSON异常:JSON文档未完全使用””异常 以下是我的步骤 public void uploadBasicImage(String fileNamePath) { String[] split = fileNamePath.split("/"); String filename = split[s

我写了一个rest调用,使用改型将图像上传到服务器。我想我已经在这里遵循了一些步骤

但我无法从这些步骤中得到任何积极的结果

我一直收到“com.google.gson.JSON异常:JSON文档未完全使用””异常

以下是我的步骤

public void uploadBasicImage(String fileNamePath) {
        String[] split = fileNamePath.split("/");
        String filename = split[split.length-1];

        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        File file = new File(path, filename +".jpg");
        try {
            path.mkdirs();
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
        MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("img", file.getName(), requestBody);

        if (ApiClient.getRefreshedToken(context) == null) {
            LogoutProcess.logout(context);
        } else {
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Interceptor.Chain chain) throws IOException {
                    Request original = chain.request();

                    Request request = original.newBuilder()
                            .header("Content-Type", "application/json")
                            .header("X-Requested-With", "XMLHttpRequest")
                            .header("X-Authorization", "Bearer " + TokenIdentifier.getTOKEN())
                            .method(original.method(), original.body())
                            .build();

                    return chain.proceed(request);
                }
            });

            Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();

            OkHttpClient client = httpClient.build();
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(Constant.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .client(client)
                    .build();

            ApiService apiService = retrofit.create(ApiService.class);
            Call<String> call = apiService.uploadImage(fileToUpload);
            call.enqueue(new Callback<String>() {
                @Override
                public void onResponse(Call<String> call, retrofit2.Response<String> response) {
                    if (response.body() != null && !response.body().isEmpty()) {
                        Snackbar.make(view, "Image uploaded", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    }
                }

                @Override
                public void onFailure(Call<String> call, Throwable t) {
                    t.printStackTrace();
                }
            });
        }

    }
public void uploadBasicImage(字符串fileNamePath){
String[]split=fileNamePath.split(“/”);
字符串文件名=split[split.length-1];
文件路径=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\u图片);
File File=新文件(路径,文件名+“.jpg”);
试一试{
path.mkdirs();
createNewFile();
}捕获(IOE异常){
e、 printStackTrace();
}
RequestBody RequestBody=RequestBody.create(MediaType.parse(“*/*”),文件);
MultipartBody.Part fileToUpload=MultipartBody.Part.createFormData(“img”,file.getName(),requestBody);
if(ApiClient.getRefreshedToken(context)==null){
注销过程。注销(上下文);
}否则{
OkHttpClient.Builder httpClient=新建OkHttpClient.Builder();
httpClient.addInterceptor(新的拦截器(){
@凌驾
公共响应拦截(Interceptor.Chain)引发IOException{
Request original=chain.Request();
请求=original.newBuilder()
.header(“内容类型”、“应用程序/json”)
.header(“X-request-With”,“XMLHttpRequest”)
.header(“X-Authorization”、“Bearer”+令牌标识符.getTOKEN())
.method(original.method(),original.body())
.build();
返回链。继续(请求);
}
});
Gson Gson=new GsonBuilder()
.setLenient()
.create();
OkHttpClient=httpClient.build();
改装改装=新改装.Builder()
.baseUrl(常量.BASE\u URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.客户(客户)
.build();
ApiService ApiService=reformation.create(ApiService.class);
Call Call=apiService.uploadImage(fileToUpload);
call.enqueue(新回调(){
@凌驾
公共void onResponse(呼叫,改装2.响应){
if(response.body()!=null&&!response.body().isEmpty()){
make(查看“上传的图像”,Snackbar.LENGTH_LONG).setAction(“Action”,null).show();
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
t、 printStackTrace();
}
});
}
}
我怎样才能解决这个异常呢?

,就像Jake说的,没有完整的堆栈跟踪很难诊断,或者知道这是在什么时候抛出的,就像Jake说的,没有完整的堆栈跟踪很难诊断,或者知道这是在什么时候抛出的