我正在使用 PHP 生成Json
从数据库查询中获取的内容。结果如下所示:
[
{
"title":"Title 1",
"description":"This is description 1",
"add_date":"2013-07-17 10:07:53"
},{
"title":"Title 2",
"description":"This is description 2",
"add_date":"2013-07-17 10:07:53"
}
]
我正在使用 Gson 来解析数据,如下所示:
public class Search{
public Search(String text){
try{
// Snipped (gets the data from the website)
Gson json = new Gson();
Map<String, Event> events = json.fromJson(resultstring, new TypeToken<Map<String, Event>>(){}.getType());
System.out.print(events.get("description"));
}catch(IOException ex){
Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class Event {
private String description;
}
这是我在尝试运行代码时收到的消息:
线程“AWT-EventQueue-0”com.google.gson.JsonSyntaxException 中的异常:java.lang.IllegalStateException:预期 BEGIN_ARRAY 但在第 1 行第 3 列是 BEGIN_OBJECT
我将如何遍历每一个来获得 的值description
,title
或两者兼而有之?