我面临一个问题,有时Json响应返回一个对象数组,有时是对象本身,我们如何在响应类中动态处理。在当前的 eg :results 有时会得到一个对象数组
"\"results\": " +
"[{" +
有时反对自己
"\"results\": " +
"{" +
例如:
我们该如何处理呢?
Gson gson = new Gson();
SearchResponse response=new SearchResponse();
response= gson.fromJson("{" +
"\"completed_in\": 0.047," +
"\"max_id\": 291771567376039936," +
"\"max_id_str\": \"291771567376039936\"," +
"\"next_page\": \"?page=2&max_id=291771567376039936&q=javacodegeeks\"," +
"\"page\": 1," +
"\"query\": \"javacodegeeks\"," +
"\"refresh_url\": \"?since_id=291771567376039936&q=javacodegeeks\"," +
"\"results\": " +
"{" +
"\"created_at\": \"Thu, 17 Jan 2013 04:58:57 +0000\"," +
"\"from_user\": \"hkokko\"," +
"\"from_user_id\": 24726686," +
"\"from_user_id_str\": \"24726686\"," +
" \"from_user_name\": \"Hannu Kokko\"," +
" \"geo\": null," +
"\"id\": 291771567376039936," +
"\"id_str\": \"291771567376039936\"," +
"\"iso_language_code\": \"en\"," +
" \"metadata\": {" +
"\"result_type\": \"recent\"}," +
"\"profile_image_url\": \"hjh\"," +
"\"profile_image_url_https\": \"kkj\"," +
"\"source\": \"<a href="hj;\"," +
"\"text\": \"Continuous Deployment: Are You Afraid It Might Work? jh\"," +
"\"to_user\": null," +
"\"to_user_id\": 0," +
"\"to_user_id_str\": \"0\"," +
"\"to_user_name\": null" +
" }," +
"\"results_per_page\": 15," +
"\"since_id\": 0," +
"\"since_id_str\": \"0\"" +
"}", SearchResponse.class);
System.out.println(response.toString());
请协助...
任何人都可以通过使用不同的罐子来实现这一目标提出任何建议吗?