以下代码为 Google 图表返回 json
public static DataTable generateDataTable(){
// Create a data table,
DataTable data = new DataTable();
ArrayList cd = new ArrayList();
cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal name"));
cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to wikipedia"));
cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population size"));
cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN, "Vegetarian?"));
data.addColumns(cd);
// Fill the data table.
try {
data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);
} catch (TypeMismatchException e) {
System.out.println("Invalid type!");
}
return data;
}
public static void main(String []args){
String json = JsonRenderer.renderDataTable(generateDataTable(), false, false).toString();
System.out.println(json);
}
但是返回的 JSON
{cols:[{id:'name',label:'Animal name',type:'string',pattern:''},{id:'link',label:'Link to wikipedia',type:'string',pattern:''},{id:'population',label:'Population size',type:'number',pattern:''},{id:'vegeterian',label:'Vegetarian?',type:'boolean',pattern:''}]}
还有什么是返回的 json 中显示的模式值{id:'name',label:'Animal name',type:'string',**pattern:''**}