我对json,google apis很新。所以请指导。
我想在'JAVA'中编写一个应用程序,通过Restful使用谷歌自定义serch api。我开始学习JSON并通过[链接] http://code.google.com/apis/customsearch/v1/overview.html我想写一些代码。json转换为java类的问题(谷歌自定义搜索)
这说明搜索的谷歌的JSON:
http://code.google.com/apis/customsearch/v1/reference.html#method_search_cse_list
参考是http://code.google.com/apis/customsearch/v1/reference.html
从i找到的参考此CustomSearch的领域将是字符串或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.
我怎么会在我的类中定义它们。什么样的数组是标题字符串或char,这个pagemap是一些约定或任何网站都可以给它自己的标签。
//类CustomSearch
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;
}
你用什么来反序列化JSON响应? – momo
我thik我会使用Gson。 –
@momo使用任何反序列化器都会对此问题产生任何影响。 –