我使用Retrofit发送图片请求并接收此Json
RestAdapter adapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint(END_POINT)
.build();
Mylistenerr listener = adapter.create(Mylistenerr.class);
File photo = new File(picturePath);
TypedFile image = new TypedFile("multipart/image/jpg", photo);
listener.setUserImage(
image,
new Callback<respostring>() {
@Override
public void success(respostring rp, Response arg1) {}
@Override
public void failure(RetrofitError arg0) {
pd.hide();
pd.dismiss();
Log.d("ERROR:", arg0.getLocalizedMessage());
}
});
}
private static class respostring {
private Content face;
private Content gender;
respostring() {}
}
class Content
{
private int confidence;
private String value;
Content(){}
public int getconf(){
return this.confidence;
}
public String getvalue(){
return this.value;
}
}
我正在接受改造 ....
public interface Mylistenerr {
@Multipart
@POST("/public/test")
void setUserImage(
@Part("image") TypedFile file,
Callback<respostring> response);
}
我的界面
{{1}}
但有改装错误。我在这里想念一下吗?
答案 0 :(得分:0)
我建议您使用Gson进行json反序列化,因为改造支持它非常好。然后你可以创建这样的类:
你的面孔:
public class Face implements Serializable {
@SerializedName("value")
public boolean value;
@SerializedName("confidence")
public int confidence;
}
您的性别等级:
public class Gender implements Serializable {
@SerializedName("value")
public String value;
@SerializedName("confidence")
public int confidence;
}
您的回复课程:
public class YourResponseType implements Serializable {
@SerializedName("face")
public Face face;
@SerializedName("gender")
public Gender gender;
}
然后你可以为你做其余的改造:
listener.setUserImage(image, new Callback<YourResonseType>() {...});
希望有所帮助!