개체가 JSON으로 반환 될 다음 결과 클래스가 있습니다.GSON - JsonSyntaxException - 7 행 4 열의 예상 이름
public class Result {
public String objectid;
public String dtype;
public String type;
public String name;
public String description;
public Result() {
this.objectid = "";
this.dtype= "";
this.type="";
this.name= "";
this.description = "";
}
public String getObjectid() {
return objectid;
}
public void setObjectid(String s) {
this.objectid = s;
}
public String getDtype() {
return dtype;
}
public void setDtype(String s) {
this.dtype= s;
}
public String getType() {
return type;
}
public void setType(String s) {
this.type = s;
}
public String getName() {
return name;
}
public void setName(String s) {
this.name = s;
}
public String getDescription() {
return description;
}
public void setDescription(String s) {
this.description = s;
}
}
구성 json은 주 .java로 읽히고 json으로 HTTP RESPONSE로 반환됩니다. 그것은 다음과 같습니다 :
{
"objectid" : "test",
"dtype" : "test",
"type" : "test",
"name" : "test",
"description" : "test" // removed
},
{
"objectid" : "test",
"dtype" : "test",
"type" : "test",
"name" : "test",
"description" : "test"
}
홈페이지 된 .java
GSON을 사용하여, 그것은 configuration.json 파일을 읽고 JSON을 반환해야한다.
내 코드 : res.toString()
나에게 문자열로 configuration.json 파일 내용을 얻을 수
Gson g = new Gson();
Result r = g.fromJson(res.toString(), Result.class);
.
내 문제 :나는 다음과 같은 예외가 발생하는 오전 :
에서 잘못된 JSON을 적용합니다예외를 com.google.gson.JsonSyntaxException : com.google.gson.stream.MalformedJsonException : 사용 JsonReader.setLenient (참) 행 7 열에서 잘못된 JSON을 수락 3
com.google.gson.JsonSyntaxException : com.google.gson.stream.MalformedJsonException : 사용 JsonReader.setLenient (참)는 7 행 3 열
모든 포인터?
왜 "이름"에 간격이 있습니까? 귀하의 오류가 나쁜 JSON – CBIII
@ ClydeByrdIII 말해, 고쳤다 미안 해요. 여전히 정확한 문제. – Namenoobie
당신은 그 Json으로부터 여러 개의'Result's를 파싱하려고합니까? 그렇다면 Json이 목록처럼 보이고 Gson에게 목록임을 알려줄 필요가 있습니다. –