我有以下结果类,其对象将以 JSON 形式返回。
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 响应返回。如下:
{
"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。
My code:
Gson g = new Gson();
Result r = g.fromJson(res.toString(), Result.class);
where res.toString()
以字符串形式获取configuration.json 文件内容。
我的问题:
我遇到以下异常:
异常 com.google.gson.JsonSyntaxException:com.google.gson.stream.MalformedJsonException:使用 JsonReader.setLenient(true) 接受第 7 行第 3 列处格式错误的 JSON
com.google.gson.JsonSyntaxException:com.google.gson.stream.MalformedJsonException:使用 JsonReader.setLenient(true) 接受第 7 行第 3 列处格式错误的 JSON
有什么指点吗?