0
我想知道,鑑於以下JSON,我如何能夠生成一個ResultSet
實例,其中攜帶的Query
值爲ppb
?什麼是由google-gson讀取的JSON的結構
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對象?
更新我的問題 – 2010-10-10 18:51:50
@Yan Cheng CHEOK那不是我的意思。無論如何,請參閱我的更新 – Bozho 2010-10-10 18:53:35
我無法控制JSON字符串。它從服務器返回。 – 2010-10-10 18:58:18