如何解析数据,我想要" CC"," CT"," TT"或者rsid,性别......这个数据是用javascript编写的?
谢谢大家〜
{
"0": {
"rrvalue": {
"CC": 0.8652407470299768,
"CT": 1.1161605636753882,
"TT": 1.4398471271298607
},
"rsid": "rs505802",
"sex": 0
},
"1": {
"rrvalue": {
"CC": 0.8655216050171408,
"CT": 1.116522870472112,
"TT": 1.4403145029090243
},
"rsid": "rs505802",
"sex": 1
}
}
答案 0 :(得分:0)
var obj = {
"0": {
"rrvalue": {
"CC": 0.8652407470299768,
"CT": 1.1161605636753882,
"TT": 1.4398471271298607
},
"rsid": "rs505802",
"sex": 0
},
"1": {
"rrvalue": {
"CC": 0.8655216050171408,
"CT": 1.116522870472112,
"TT": 1.4403145029090243
},
"rsid": "rs505802",
"sex": 1
}
}
console.log( obj[ "0" ][ "rrvalue" ][ "CC" ] );
console.log( obj[ "0" ][ "rrvalue" ][ "CT" ] );
console.log( obj[ "0" ][ "rrvalue" ][ "TT" ] );
了解如何访问JSON / Object值here
答案 1 :(得分:0)
我认为这会对你有帮助。
var data = {
"0": {
"rrvalue": {
"CC": 0.8652407470299768,
"CT": 1.1161605636753882,
"TT": 1.4398471271298607
},
"rsid": "rs505802",
"sex": 0
},
"1": {
"rrvalue": {
"CC": 0.8655216050171408,
"CT": 1.116522870472112,
"TT": 1.4403145029090243
},
"rsid": "rs505802",
"sex": 1
}
}
/* Via jquery */
$.each(data,function(key,value){
console.log("LOOP -- > " + key);
$.each(data[key],function(k1,v1){
if(k1 === "rrvalue"){
$.each(data[key][k1],function(k2,v2){
console.log(k2,v2);
});
} else {
console.log(k1,v1);
}
});
});
/* Via javascript */
for(var i in data){
console.log("for Loop " + i);
for(var j in data[i]){
if(j === "rrvalue") {
for(var k in data[i][j]){
console.log(k + " " + data[i][j][k]);
}
} else {
console.log(j + " " + data[i][j]);
}
}
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
答案 2 :(得分:-2)