にあった:アンドロイドGSONはBEGIN_ARRAYを期待したがBEGIN_OBJECTは、私は、次のJSONを解析しようとしています行1列2
{
"Message": "The request is invalid.",
"ModelState": {
"": [
"Name [email protected] is already taken.",
"Email '[email protected]' is already taken."
]
}
}
私が使用したコード:
ErrorRequest page = gson.fromJson(response.getResponseString(), ErrorRequest.class);
をしかし、私はエラーを取得していました: com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:期待BEGIN_ARRAYしかしBEGIN_OBJECTは行1列にあった2つの
私のPOJOクラスは、次のとおりです。 ErrorRequest.Java
package com.devinedesign.cleanride.domain;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
public class ErrorRequest
{
@SerializedName("Message")
private String message;
@SerializedName("ModelState")
private List<ModelState> modelState;
public ErrorRequest(String message,List<ModelState> modelState)
{
this.message = message;
this.modelState = modelState;
}
public String getMessage()
{
return message;
}
public void setMessage(String message)
{
this.message = message;
}
public List<ModelState> getModelState()
{
return modelState;
}
public void setModelState(List<ModelState> modelState)
{
this.modelState = modelState;
}
}
ModelState.Java
package com.devinedesign.cleanride.domain;
import com.google.gson.annotations.SerializedName;
public class ModelState
{
@SerializedName("ModelState")
private String modelState;
public ModelState(String modelState)
{
this.modelState = modelState;
}
public String getModelState() {
return modelState;
}
public void setModelState(String modelState) {
this.modelState = modelState;
}
}
JSONの配列の前に空のキー文字列があるはずですか? –
さて、私のクライアントはAPIでそれを私に提供しました。それが私がエラーを受けた理由ですか? – aaa111
'{ "メッセージ ":"要求が無効です "のように見えるはずです。"、 "ModelState":[ "名前はすでに[email protected]です。"、 "メール@ c @ gmail。 comは既に撮影されています。 " ] } '。空のキーはちょうどかなり単純なjson応答を抽象化しているようです。 – zgc7009