Tengo un problema al manejar los datos JSON dentro de JavaScript, específicamente en lo que respecta al uso de los datos como una matriz y el acceso e iteración a través de valores individuales. El archivo JSON está estructurado de la siguiente manera:JSON to javaScript array
{
"head": {
"vars": [ "place" , "lat" , "long" , "page" ]
} ,
"results": {
"bindings": [
{
"place": { "type": "literal" , "value": "Building A" } ,
"lat": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "10.3456" } ,
"long": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "-1.2345" } ,
"page": { "type": "uri" , "value": "http://www.example.com/a.html" }
} ,
{
"place": { "type": "literal" , "value": "Building B" } ,
"lat": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "11.3456" } ,
"long": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "-2.2345" } ,
"page": { "type": "uri" , "value": "http://www.example.com/b.html" }
} ,
{
"place": { "type": "literal" , "value": "Building C" } ,
"lat": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "12.3456" } ,
"long": { "datatype": "http://www.w3.org/2001/XMLSchema#float" , "type": "typed-literal" , "value": "-3.2345" } ,
"page": { "type": "uri" , "value": "http://www.example.com/c.html" }
}
]
}
}
Quiero ser capaz de convertir esto en una matriz de JavaScript de la siguiente manera con el fin de que puedo iterar a través de él y sacar los valores para cada lugar en orden:
var locations = [
['Building A',10.3456,-1.2345,'http://www.example.com/a.html'],
['Building B',11.3456,-2.2345,'http://www.example.com/b.html'],
['Building C',12.3456,-3.2345,'http://www.example.com/c.html']
];
¿Alguien tiene algún consejo sobre cómo lograr esto? He intentado el siguiente, pero recoge el "tipo" dentro del JSON, en lugar de sólo el valor:
$.each(JSONObject.results.bindings, function(i, object) {
$.each(object, function(property, object) {
$.each(object, function(property, value) {
value;
});
});
});
Cualquier ayuda, sugerencias, consejos o correcciones sería muy apreciada.
Ahhh ... tan simple muchas gracias –
tantos se olvide de ver nuestra empuje (er) cuando necesitar un arreglo –