I have the following JSON:
{
"$SP": {
"0": "92",
"1": "00:01:36.340",
"2": "00:05:48.929\n"
},
"$MT": {
"0": "91",
"1": "00:00:34.187",
"2": "00:18:44.001\n"
}
}
I need a function that looks for the key name and then look for a number inside it, and return the whole object. For example:
json("$MT", "91");
Expected return:
"$MT": {
"0": "91",
"1": "00:00:34.187",
"2": "00:18:44.001\n"
}
I have the following function:
var json = {};
function addJson(data){
var chave;
for(var i in data){
if(i == 0){
chave = data[i];
json[chave] = {};
}else{
json[chave][i-1] = data[i];
}
}
}
But it returns only a single key.