I was wondering, given the following JSON, how I can produce a ResultSet
instance, which carry Query
valued 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);
}
}
Currently, here is what I get :
{"ResultSet":{"Query":"ppb"}}
{}
null
Without modified the String, how can I get a correct Java object?