Created
October 19, 2017 04:02
-
-
Save ppineda32/c73f55937e999f2a1ca82f31e9281dd1 to your computer and use it in GitHub Desktop.
imprimir json y xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use-strict' | |
var dictionary = {}; | |
function addValues(){ | |
var llave = document.getElementById("llave").value; | |
var valor = document.getElementById("valor").value; | |
dictionary[llave] = valor; | |
} | |
function printJSON(){ | |
var string = '{<br>"diccionario":[<br>' | |
for(var llave in dictionary){ | |
var valor = dictionary[llave]; | |
var tipo = "String"; | |
if(!isNaN(valor)){ | |
tipo = "Number"; | |
}else if(valor=="true"||valor=="false"){ | |
tipo = "Bool"; | |
} | |
string += '{"llave":"'+llave+'",<br>"valor":"'+valor+'",<br>"tipo":"'+tipo+'"},<br>'; | |
} | |
string = string.slice(0,string.length-5); | |
string += "<br>"; | |
string += ' ]<br>}' | |
document.getElementById("format").innerHTML=string; | |
} | |
function printXML(){ | |
var string = '<dictionary><br>' | |
for(var llave in dictionary){ | |
var valor = dictionary[llave]; | |
var tipo = "String"; | |
if(!isNaN(valor)){ | |
tipo = "Number"; | |
}else if(valor=="true"||valor=="false"){ | |
tipo = "Bool"; | |
} | |
string += '<element><br>'; | |
string += '<llave>'+llave+'</llave><br>'; | |
string += '<tipo>'+tipo+'</tipo><br>'; | |
string += '<valor>'+valor+'</valor><br>'; | |
string += '</element><br>'; | |
} | |
string += '</dictionary>' | |
document.getElementById("format").innerHTML=string; | |
} | |
window.onload = function(){ | |
var button = document.getElementById("Add"); | |
button.addEventListener("click",addValues); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment