0

我正在使用谷歌趋势来获取特定关键字的趋势。它将返回 JSON,但主要问题是我想创建保存数据并在 java 代码中用作数组列表的类。当我得到如下结果时,我很困惑它的类结构是什么

{"version":"0.6","status":"ok","sig":"1248242565",
 "table":
    { "cols":  
       [{"id":"date","label":"Date","type":"date","pattern":""}, 
        {"id":"query0","label":"linkedin","type":"number","pattern":""},
        {"id":"query1","label":"facebook","type":"number","pattern":""}],

       "rows":[{"c":[{"v":new Date(2004,0,1),"f":"January 2004"},{"v":0.0,"f":"0"},{"v":0.0,"f":"0"}]},
               {"c":[{"v":new Date(2004,5,1),"f":"June 2004"},{"v":0.0,"f":"0"}, {"v":0.0,"f":"0"}]},
               {"c":[{"v":new Date(2004,8,1),"f":"September 2004"},{"v":0.0,"f":"0"},{"v":0.0,"f":"0"}]},
               {"c":[{"v":new Date(2013,9,1),"f":"October 2013"},{"v":1.0,"f":"1"},{"v":83.0,"f":"83"}]}]
    }
 } 

如果我搜索两个单独的单词,它将在搜索查询中返回行和列,结果类似于 JSON 之上。我不知道如何制作 Trend.java 类和包含所有这些信息的列表对象

4

1 回答 1

0

你将如何代表这些价值观?我会去List<HashMap<String, String>>实施。

您可以将行中的每个项目分配给 a HashMap,并将列标题作为key. 所以:

HashMap<String, String> row = new HashMap<String, String>();
row.put("id", "c");
// add the rest.

然后您可以循环浏览每一行,并按名称请求列数据。这也将产生一些语义上非常好的代码!

于 2013-10-03T15:36:29.380 回答