オブジェクトが 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;
}
}
メインの.javaを読み取り、HTTP RESPONSEとしてjsonとして返される構成jsonがあります。以下の通りです。
{
"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 を返す必要があります。
私のコード:
Gson g = new Gson();
Result r = g.fromJson(res.toString(), Result.class);
ここでres.toString()
、configuration.json ファイルの内容を文字列として取得します。
私の問題:
次の例外が発生しています。
例外 com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: JsonReader.setLenient(true) を使用して、行 7 列 3
com.google.gson.JsonSyntaxException: com.google.gson.streamで不正な形式の JSON を受け入れます.MalformedJsonException: JsonReader.setLenient(true) を使用して、行 7、列 3 で不正な形式の JSON を受け入れます
ポインタはありますか?