json - 如何解析 json(items : [{...}])
问题描述
信息.json
{
"lastBuildDate": "Mon, 16 Jul 2018 01:28:44 +0900",
"total": 2,
"start": 1,
"display": 2,
"items": [{
"title": "<b>설빙</b> 경기광명철산점",
"link": "http://sulbing.com/",
"category": "카페,디저트>빙수",
"description": "디저트 카페, 빙수, 토스트, 커피, 스무디, 녹차라떼, 오미자차 등 판매.",
"telephone": "02-2611-1478",
"address": "경기도 광명시 철산동 410",
"roadAddress": "경기도 광명시 오리로856번길 8-1",
"mapx": "300065",
"mapy": "542034"
}, {
"title": "<b>설빙</b> 하안점",
"link": "",
"category": "카페,디저트>빙수",
"description": "경기도 광명시 하안동 위치, 디저트카페, 빙수 전문점.",
"telephone": "02-899-0503",
"address": "경기도 광명시 하안동 34-3",
"roadAddress": "경기도 광명시 하안로 309 세인빌딩",
"mapx": "301042",
"mapy": "540690"
}]
}
我想解析这个 json 文件。
其中,我想解析 ' items : [{...}]' 的内容中的内容,但是教程并没有告诉我该怎么做。
我使用 Java,但 Kotlin 也可以(Android)
并且标签<b> <\b>
会被gson删除吗?还是我应该删除它?如果是后者呢?
解决方案
我已经按照 json 结构构建了类:
class Information{
public Date lastBuildDate;
public int total;
public int start;
public int display;
public List<Item> items;
}
class Item{
public String title;
public String link;
public String category;
public String description;
public String telephone;
public String address;
public String roadAddress;
public String mapx;
public String mapy;
}
在简单的 pasre json 之后,通过以下方式进行对象:
new Gson().fromJson(json, Information.class)
我已将日期更改为2018-07-16
原始 json。如果你想使用特殊的日期格式,你需要实现JsonSerializer<Date>
.
推荐阅读
- amazon-s3 - 将保险柜机密存储在 S3 存储桶中
- typescript - 带有打字稿和敲除(foreach)的选择框模型
- php - 中心水印 (fpd fpdi)
- python - Python - 在二维数组内计数 - OpenCV
- css - `position: fixed` 是否会破坏混合混合模式,是否有解决方法?
- r - R map mit ggplot2 - 错误:美学必须是长度1或与数据相同
- javascript - Firestore 取消订阅更新
- python - 以 UUID 字段作为主键的 Django 管理员 UserChangeForm
- r - 如何在ggplot上注释行?
- java - Android WebView 代理设置