0

I´m getting that error message when I´m trying to format a JSON Object, I´m trying to store in a variable the population in this API response:

[
    {
        "countryCode": "ru",
        "countryName": "Russia",
        "population": [
            {
                "year": "2016",
                "data": "144342396"
            }
        ]
    }
]

It´s my first time working with JSON so I´m sorry if it´s just a silly mistake. :(

function definir_tabla(id_tabla) {
    var codigo;
    switch (id_tabla) {
        case "tabla_rusia":
            codigo = "ru";
            solicitar_datos(id_tabla,codigo);
            break;

    }
}

function solicitar_datos(tabla, codigo_iso) {
    var habitantes = $.get('http://inqstatsapi.inqubu.com/?api_key=xxxxxxxxxx&data=population&countries=ru&years=2016');
    var numero=JSON.parse(habitantes);;
    console.log(numero);
    document.getElementById(tabla + "_habitantes").innerText = habitantes;
}
Jeremy
  • 1,447
  • 20
  • 40
  • 1
    Might not be the best idea to post your API key publicly. – CertainPerformance Dec 03 '18 at 05:07
  • 1
    `$.get` is asynchronous, if you want to store the response in a variable, you'll have to use `await` or call `.then` on it or have a success method, or something like that – CertainPerformance Dec 03 '18 at 05:11
  • No pude contestar antes que cerraran la pregunta, si te es util aun, por favor revisa este ejemplo https://gist.github.com/ilmoralito/74f036a12f658916b5760017802fd8a4 – Mario Dec 03 '18 at 05:33
  • @user615274 Gracias!!, lo probare dentro de poco; tengo que hacer unos cambios al codigo para poderme enfocar en esta parte – Jeremy Dec 03 '18 at 06:04

0 Answers0