0

I am trying to make a discord bot that parses a json response, but I'm not entirely sure on how to do so.

This is an example response:

[{"beatmap_id":"146929","score":"1467874","maxcombo":"182","count50":"1","count100":"41","count300":"475","countmiss":"10","countkatu":"20","countgeki":"72","perfect":"0","enabled_mods":"0","user_id":"1009","date":"2020-02-29 11:15:49","rank":"A","pp":"38.767826"},{"beatmap_id":"245658","score":"1013358","maxcombo":"244","count50":"0","count100":"6","count300":"158","countmiss":"1","countkatu":"5","countgeki":"24","perfect":"0","enabled_mods":"0","user_id":"1009","date":"2020-02-29 11:13:05","rank":"A","pp":"49.74563"},{"beatmap_id":"245658","score":"34162","maxcombo":"42","count50":"0","count100":"1","count300":"27","countmiss":"1","countkatu":"0","countgeki":"4","perfect":"0","enabled_mods":"0","user_id":"1009","date":"2020-02-29 11:12:19","rank":"A","pp":"12.399677"},{"beatmap_id":"1128411","score":"4785282","maxcombo":"350","count50":"23","count100":"292","count300":"1117","countmiss":"51","countkatu":"93","countgeki":"132","perfect":"0","enabled_mods":"0","user_id":"1009","date":"2020-02-29 11:10:52","rank":"C","pp":"12.770388"},{"beatmap_id":"431147","score":"209504","maxcombo":"105","count50":"0","count100":"4","count300":"73","countmiss":"1","countkatu":"3","countgeki":"9","perfect":"0","enabled_mods":"0","user_id":"1009","date":"2020-02-29 11:04:05","rank":"A","pp":"22.695227"}]

How would I just get the first "beatmap_id" key and return the value of it with Gson?

I'm fairly new to coding and I need a push in the right direction, so could someone give me an example, or link me to the part of the documentation i need to learn this?

Any help is appreciated, thanks!

Deagan Muir
  • 103
  • 4
  • 13
  • 1
    Create a DTO class that you will read this string into. This seems to be an array of objects, so you will need to parse into an array of the DTO you created. – Koray Tugay Sep 28 '20 at 18:00
  • 1
    https://howtodoinjava.com/gson/gson-parse-json-array/ This should help you. – Koray Tugay Sep 28 '20 at 18:01
  • 1
    Does this answer your question? [How to parse JSON in Java](https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – bitfox Sep 28 '20 at 18:39

1 Answers1

0

You should create DTO class for same followed by keys which are in the response.

You can view this blog for understanding gson.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Rajan Rana
  • 21
  • 1