我想知道,给定以下 JSON,我如何生成一个带有value的ResultSet
实例?Query
ppb
package jsontest;
import com.google.gson.Gson;
/**
*
* @author yccheok
*/
public class Main {
public static class ResultSet {
public String Query;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final String s = "{\"ResultSet\":{\"Query\":\"ppb\"}}";
System.out.println(s);
Gson gson = new Gson();
ResultSet resultSet = gson.fromJson(s, ResultSet.class);
// {}
System.out.println(gson.toJson(resultSet));
// null?
System.out.println(resultSet.Query);
}
}
目前,这是我得到的:
{"ResultSet":{"Query":"ppb"}}
{}
null
如果不修改字符串,我怎样才能得到正确的 Java 对象?