How can I extract the data from this JSON URL using javascript and html? [duplicate]

0

I want to extract the data from a using and . What I need is to show the values of the properties id and name .

  • This is the URL of the API.
  • The answer is this:

        {
          "mohademago": {
            "id": 4294825,
            "name": "mohademago",
            "profileIconId": 1594,
            "revisionDate": 1491930966000,
            "summonerLevel": 30
          }
        }
    
asked by Guillexd 15.04.2017 в 20:44
source

1 answer

0

The easiest way is to use

  

jQuery

objetoJS = jQuery.parseJSON(JSON);

then you can use it as any JS object:

objetoJS["attributo"]

in your case it would work something like that

function parseJSON(){

            $.get( "https://las.api.pvp.net/api/lol/las/v1.4/summoner/by-
                    name/mohademago",
                    {api_key:"RGAPI-ab75f917-5785-45e5-aa33-df9755cd4b66"}
                 ).done(function( JSON ) {  


                var objectJS = jQuery.parseJSON(JSON);
                var ID=objectJS['mohademago']['id'];
                var NAME=objectJS['mohademago']['name'];

            }); 
        }
    
answered by 15.04.2017 в 21:01