【发布时间】:2013-03-14 14:13:22
【问题描述】:
每个news 条目都有三个 东西:title、content和date。
条目是从数据库中检索的,我想在我的应用程序中使用 JSONObject 和 JSONArray 读取它们。但是,我不知道如何使用这些类。
这是我的 JSON 字符串:
[
{
"news":{
"title":"5th title",
"content":"5th content",
"date":"1363197493"
}
},
{
"news":{
"title":"4th title",
"content":"4th content",
"date":"1363197454"
}
},
{
"news":{
"title":"3rd title",
"content":"3rd content",
"date":"1363197443"
}
},
{
"news":{
"title":"2nd title",
"content":"2nd content",
"date":"1363197409"
}
},
{
"news":{
"title":"1st title",
"content":"1st content",
"date":"1363197399"
}
}
]
【问题讨论】:
-
首先,创建一个名为 News 的类,其中包含 3 个字段:标题、内容和日期。
-
阅读有关如何使用 java json 解析器的文档。