Skip to main content
se añadieron 120 caracteres en el cuerpo
Origen Enlace
Jaime
  • 7.3k
  • 2
  • 11
  • 23

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

JSONObject json = readJsonFromUrl("http://ddragon.leagueoflegends.com/cdn/12.7.1/data/es_ES/champion.json"); 
Set<String> nombres = json.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]

Si necesitas iterarlo uno por uno:

for (String  nombre: nombres) {
     System.out.println(nombre);
}

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

JSONObject json = readJsonFromUrl("http://ddragon.leagueoflegends.com/cdn/12.7.1/data/es_ES/champion.json"); 
Set<String> nombres = json.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

JSONObject json = readJsonFromUrl("http://ddragon.leagueoflegends.com/cdn/12.7.1/data/es_ES/champion.json"); 
Set<String> nombres = json.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]

Si necesitas iterarlo uno por uno:

for (String  nombre: nombres) {
     System.out.println(nombre);
}
se eliminaron 4 caracteres en el cuerpo
Origen Enlace
Jaime
  • 7.3k
  • 2
  • 11
  • 23

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

JSONObject json = readJsonFromUrl("http://ddragon.leagueoflegends.com/cdn/12.7.1/data/es_ES/champion.json"); 
Set<String> nombres = myObjectjson.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

Set<String> nombres = myObject.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

JSONObject json = readJsonFromUrl("http://ddragon.leagueoflegends.com/cdn/12.7.1/data/es_ES/champion.json"); 
Set<String> nombres = json.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]
Origen Enlace
Jaime
  • 7.3k
  • 2
  • 11
  • 23

Primero, obtienes el objeto data con .getJSONObject. Luego, dado que los nombres que necesitas son las claves de ese objeto, pues los obtienes tienes simplemente con el método .keySet(). Quedaría:

Set<String> nombres = myObject.getJSONObject("data").keySet();
System.out.println(nombres);

Dando como salida en la consola:

[Jax, Sona, Tristana, Yuumi, Seraphine, Varus, Kaisa, Fiora, Singed, Samira, TahmKench, Leblanc, Thresh, Karma, Lillia, Jhin, Rumble, Udyr, LeeSin, Yorick, Ornn, Kayn, Neeko, Kassadin, Sivir, MissFortune, Senna, Draven, Yasuo, Kayle, Rell, Shaco, Renekton, Hecarim, Fizz, KogMaw, Yone, Maokai, Lissandra, Jinx, Urgot, Fiddlesticks, Galio, Pantheon, Talon, Gangplank, Sett, Ezreal, Gnar, Teemo, Annie, Mordekaiser, Azir, Kennen, Riven, Chogath, Aatrox, Poppy, Taliyah, Illaoi, Pyke, Heimerdinger, Alistar, XinZhao, Lucian, Volibear, Sejuani, Nidalee, Garen, Leona, Zed, Blitzcrank, Rammus, Velkoz, Caitlyn, Trundle, Kindred, Renata, Akshan, Vex, Quinn, Ekko, Nami, Swain, Aphelios, Sylas, Taric, Syndra, Rakan, Skarner, Gwen, Braum, Veigar, Xerath, Corki, Nautilus, Ahri, Jayce, Darius, Tryndamere, Janna, Elise, Vayne, Brand, Zoe, Graves, Soraka, Xayah, Viego, Karthus, Vladimir, Zilean, Katarina, Shyvana, Warwick, Ziggs, Kled, Khazix, Olaf, TwistedFate, Nunu, Qiyana, Rengar, Bard, Irelia, Ivern, MonkeyKing, Ashe, Kalista, Akali, Vi, Amumu, Lulu, Morgana, Nocturne, Diana, AurelionSol, Zyra, Viktor, Cassiopeia, Nasus, Twitch, DrMundo, Zeri, Orianna, Evelynn, RekSai, Lux, Sion, Camille, MasterYi, Ryze, Malphite, Anivia, Shen, JarvanIV, Malzahar, Zac, Gragas]