-2

information.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"
}]
}

I'd like to parse this json file.

Among them, I would like to parse the contents within the contents of ' items : [{...}]' But the tutorials doesn't tell me how to do that.

I use Java, but Kotlin could do also(Android)

And will the tag <b> <\b> be removed by gson? Or should I remove it? What if the latter?

Beri
  • 11,470
  • 4
  • 35
  • 57
  • 1
    Have you any code? And did you tried this https://stackoverflow.com/questions/29965764/how-to-parse-json-file-with-gson ? – Beri Jul 15 '18 at 17:04

2 Answers2

0

I've build classes following by json structure:

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;
}

After that simple pasre json to object by the following:

new Gson().fromJson(json, Information.class)

I've change date to 2018-07-16 from original json. If you want use specail date format, you need to implement JsonSerializer<Date>.

Maxim Kasyanov
  • 938
  • 5
  • 14
0

It seems like you allready use gson.
But if it is an option for you to use something different you could take a look at Media Framework.
It works well and also supports serializing. Here are some examples.
The documentation is still not complete but i think the most things are self describing

Niton
  • 189
  • 4
  • 16