【发布时间】:2019-03-07 13:13:08
【问题描述】:
我已经从相机捕获图像并通过上传 API 上传,现在我已经成功响应:
{
"msg": "Image Upload Successful",
"status": 1,
"image": "115648975487_1551435779.png"
}
我很困惑在共享首选项中保存“图像”名称并在下一次 API 调用中将此名称作为参数发送。
这是我通过 Retrofit API 上传图片的代码:
public void imageUpload(final String imageEncoded){
file = new File(imageEncoded);
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
builder.addFormDataPart("image", file.getName(), RequestBody.create(MediaType.parse("multipart/form-data"), file));
ApiCall.callPostRetrofit(context, AppConstants.uploadImage, builder, new ApiCallBackListner() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String msg = jsonObject.getString("msg");
String status = jsonObject.getString("status");
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(String error) {
}
});
}
【问题讨论】:
-
试试 GSON。这是解析Json的更好方法。
标签: android sharedpreferences retrofit retrofit2 jsonresponse