I've created this example to illustrate an attempt to list JSON
searching for separate key and value:
var meuArray = {
"1": "Administra\u00e7\u00e3o",
"2": "Agronomia",
"3": "Arquitetura e Urbanismo",
"4": "Artes C\u00eanicas",
"5": "Artes Visuais",
"6": "Biblioteconomia",
"7": "Biologia",
"8": "Biomedicina",
"9": "Biotecnologia",
"10": "Ci\u00eancia da Computa\u00e7\u00e3o",
"11": "Ci\u00eancias Ambientais",
"12": "Ci\u00eancias Biol\u00f3gicas",
"13": "Ci\u00eancias Cont\u00e1beis",
"14": "Ci\u00eancias Econ\u00f4micas",
"15": "Ci\u00eancias Sociais",
"16": "Comunica\u00e7\u00e3o Social",
"17": "Dan\u00e7a",
"18": "Design de Ambientes",
"19": "Design de Moda",
"20": "Design Gr\u00e1fico",
"21": "Dire\u00e7\u00e3o de Arte",
"22": "Direito",
"23": "Ecologia e An\u00e1lise Ambiental",
"24": "Educa\u00e7\u00e3o F\u00edsica",
"25": "Educa\u00e7\u00e3o Musical",
"26": "Enfermagem",
"27": "Engenharia Ambiental",
"28": "Engenharia Civil",
"29": "Engenharia de Alimentos",
"30": "Engenharia de Computa\u00e7\u00e3o",
"31": "Engenharia de Minas",
"32": "Engenharia de Produ\u00e7\u00e3o",
"33": "Engenharia de Software",
"34": "Engenharia El\u00e9trica",
"35": "Engenharia Florestal",
"36": "Engenharia Mec\u00e2nica",
"37": "Engenharia Qu\u00edmica",
"38": "Estat\u00edstica",
"39": "Farm\u00e1cia",
"40": "Filosofia",
"41": "F\u00edsica",
"42": "Fisioterapia",
"43": "Geografia",
"44": "Gest\u00e3o da Informa\u00e7\u00e3o",
"45": "Hist\u00f3ria",
"46": "Jormalismo",
"47": "Letras",
"48": "Matem\u00e1tica",
"49": "Matem\u00e1tica Industrial",
"50": "Medicina",
"51": "Medicina Veterinaria",
"52": "Museologia",
"53": "M\u00fasica",
"54": "Musicoterapia",
"72": "newCi\u00eancia",
"55": "Nutri\u00e7\u00e3o",
"56": "Odontologia",
"57": "Pedagogia",
"58": "Psicologia",
"59": "Publicidade e Propaganda",
"60": "Qu\u00edmica",
"61": "Rela\u00e7\u00f5es P\u00fablicas",
"62": "Servi\u00e7o Social",
"63": "Sistemas de Informa\u00e7\u00e3o",
"64": "Zootecnia"
};
function print(meuArray) {
var tamPerson = Object.keys(meuArray).length;
// alert(tamPerson);
for (var i = 0; i < tamPerson; i++) {
$("#parag").append((Object.keys(meuArray)[i]) + " " + meuArray[i] + "<br />");
};
};
print(meuArray);
// $("#parag").append((Object.keys(meuArray)[0]) + " " + meuArray[0] + "<br />");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><pid="parag"></p>
I forgot to say an important detail, that list is in alphabetical order (in value) so I need the 'keys' and their 'values' appearing in that same order of the original 'associative array'.
You may notice that in the Gabriel and Samir examples the newCiencia 72 was at the bottom of the list (out of the original order) when in fact it is in the 'associative array' between keys 54 and 55, and that's where it should be listed because this list goes to a select and needs to be in alphabetical order.
How to print the list in the same order as the 'associative array' with their respective keys and values, somebody save me?
Example available also on jsfiddle