我对 json、google apis 很陌生。所以请指导。
我正在尝试在“JAVA”中编写一个应用程序,该应用程序将通过 Restful 使用谷歌自定义 serch api。我开始学习 json 并通过 [link] http://code.google.com/apis/customsearch/v1/overview.html我想写一些代码。
这显示了搜索 google 的 json:
http ://code.google.com/apis/customsearch/v1/reference.html#method_search_cse_list
参考是http://code.google.com/apis/customsearch/v1/reference.html
从参考资料中,我发现此 CustomSearch 的哪些字段将是 String 或 int 或任何其他数据类型。他们还定义了每个对象的结构。
但我面临一些数据类型的问题:
items.title array The title of the search result, in plain text.
items.snippet array The snippet of the search result, in plain text.
items.pagemap object Contains pagemap information for this search result.
items.pagemap.value array Pagemap information, keyed by the name of this pagemap.
items.pagemap.value.value object The actual pagemap information.
我将如何在我的课堂上定义它们。什么样的数组是标题字符串或字符,这个页面地图是一些约定,或者任何网站都可以给出自己的标签。
// 自定义搜索类
public class CustomSearch {
public URL getURL() throws MalformedURLException{
return url.getURL();
}
@Key ("items") ArrayList<SearchResult> results;
private @Key SearchURL url;
private @Key Query queries;
}
// 班级
class SearchResult {
public SearchResult(){
}
public String getTitle(){
return title;
}
public String getLink(){
return link;
}
public String getSnippet(){
return snippet;
}
private @Key String title; // is this right ?
private @Key String htmlTitle;
private @Key String link;
private @Key String snippet; // is this right ?
private @Key String htmlSnippet;
}