varlet json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (varlet ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (varlet ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
varlet tmp = [];
for (varlet i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].name,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].type,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].value]);
console.log("tmp --> ",tmp);
}
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].name,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].type,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].value]);
console.log("tmp --> ",tmp);
}
let json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (let ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (let ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
let tmp = [];
for (let i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].name,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].type,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].value]);
console.log("tmp --> ",tmp);
}
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].valuemetadatas[0].name,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].type,
json["contextResponses"][i].contextElement.attributes[0].metadatas]metadatas[0].value]);
console.log("tmp --> ",tmp);
}
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas]);
console.log("tmp --> ",tmp);
}
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].name,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].type,
json["contextResponses"][i].contextElement.attributes[0].metadatas[0].value]);
console.log("tmp --> ",tmp);
}
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
// tu Json"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas]);
console.log("tmp --> ",tmp);
}
EsperoModifique el JSON pensando mas menos en lo que tu necesitas para que lo veas, y al final agregue un for en el que la DATA queda en el formato que tu necesitas (puedes hacerte igual una forma de como hacerlo en caso de que no se exactamente lo que necesitas). Aun así igual avísame en caso de que no sea lo que necesitas y si es posible entregarme un poco mas de detalles para dar una respuesta mas certera.
Espero si aun no habías podido solucionarlo espero esto te sirva o si tienes una forma más fácil de hacer lo pedido comparte :)
PD: Es solo para recorrer el objeto completo si necesitas mas cosas avisa.
PD: Perdón la tardanza no había tenido mucho tiempo y una actualización me dejo la embarrada en mi note xD.
var json = {
// tu Json
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
Espero si aun no habías podido solucionarlo espero esto te sirva o si tienes una forma más fácil de hacer lo pedido comparte :) PD: Es solo para recorrer el objeto completo si necesitas mas cosas avisa.
var json = {
"subscriptionId" : "5a268a598dc68904bbc7b3cf",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp001",
"attributes" : [
{
"name" : "Tem_int",
"type" : "float",
"value" : 2,
"metadatas" : [
{
"name" : "accuracy",
"type" : "Float",
"value": 2 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
},
{
"contextElement" : {
"type" : "Temperatura",
"isPattern" : "false",
"id" : "S_Temp002",
"attributes" : [
{
"name" : "Tem_int1",
"type" : "float1",
"value" : 3,
"metadatas" : [
{
"name" : "accuracy1",
"type" : "Floa1t",
"value": 3 }
]
},
{
"name" : "Tem_out",
"type" : "Integer",
"value" : 1
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
};
for (var ele in json) {
//aquí para los que son objetos
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
function eachobject(json) {
for (var ele in json) {
if (typeof(json[ele]) == 'object') {
eachobject(json[ele]);
} else {
console.log('ele --> ', ele, ' - ', json[ele]);
console.log('typo del ele --> ', typeof(json[ele]));
console.log(' --------------------- ');
}
}
}
var tmp = [];
for (var i = 0; i < json["contextResponses"].length; i++) {
console.log("Attributes --> ", json["contextResponses"][i]);
tmp.push([json["contextResponses"][i].contextElement.id,
json["contextResponses"][i].contextElement.type,
json["contextResponses"][i].contextElement.attributes[0].name,
json["contextResponses"][i].contextElement.attributes[0].type,
json["contextResponses"][i].contextElement.attributes[0].value,
json["contextResponses"][i].contextElement.attributes[0].metadatas]);
console.log("tmp --> ",tmp);
}
Modifique el JSON pensando mas menos en lo que tu necesitas para que lo veas, y al final agregue un for en el que la DATA queda en el formato que tu necesitas (puedes hacerte igual una forma de como hacerlo en caso de que no se exactamente lo que necesitas). Aun así igual avísame en caso de que no sea lo que necesitas y si es posible entregarme un poco mas de detalles para dar una respuesta mas certera.
Espero si aun no habías podido solucionarlo espero esto te sirva o si tienes una forma más fácil de hacer lo pedido comparte :)
PD: Es solo para recorrer el objeto completo si necesitas mas cosas avisa.
PD: Perdón la tardanza no había tenido mucho tiempo y una actualización me dejo la embarrada en mi note xD.