我正在尝试获取字符串请求,但它会像这样给出错误
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
我的API输出是这样的:
{
"status": true,
"message": "Video uploaded successfully!",
"data": {
"video_name": "674631516178278_abc2.mp4",
"video_thumbnail": "674631516178278_thumb0017.jpg"
}
}
回复代码:
@Override
public void onResponse(Call<String> call, Response<String> response) {
try {
if (response.body() != null)
Log.e("UploadResponse>>>", response.body());
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
} catch (Exception e) {
e.printStackTrace();
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
}
}
答案 0 :(得分:3)
试试这个
@Override
public void onResponse(Call<ResponseBody> call, Response< ResponseBody > response) {
try {
if (response.body() != null)
Log.e("UploadResponse>>>", response.body());
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
} catch (Exception e) {
e.printStackTrace();
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
}
}
答案 1 :(得分:0)
我也面临类似的问题。 Dattatray Nande提供的答案是,只需在Retrofit.Builder中添加ScalarsConverterFactory.create()即可。
此外,别忘了在界面中添加如下所示的内容类型
@Headers("Content-Type: text/html")
@GET("/apiMethod")
Call<String> YourAPIFunction();
答案 2 :(得分:0)
.addConverterFactory(ScalarsConverterFactory.create()) .addxxxx
答案 3 :(得分:-1)
错误提示您要在String正文中获取结果。 如果你想这样做 只需在Retrofit.Builder中添加ScalarsConverterFactory.create()。
$sql = "SELECT * FROM doorsensor ORDER BY status WHERE id = (SELECT MAX(id) FROM doorsensor)";
在应用程序级别的build.gradle中使用改造实施。
实现'com.squareup.retrofit2:converter-scalars:2.1.0'