简体   繁体   English

从多级JSON对象中选择性地提取数据

[英]Selectively extract data from multi-level JSON object

I have a multi-level JSON object which is contains an array of 143 other objects. 我有一个多级JSON对象,其中包含143个其他对象的数组。

Running console.log(obj) on this object displays: 在此对象上运行console.log(obj)将显示:

0: Object
  ActFTEs: 0.00
  Actual: 11111
  Bud_Month: "October"
  FY_CD: 2013
  Mission_Name: "RST"
__proto__: Object
1: Object
  ActFTEs: 0.00
  Actual: 10000
  Bud_Month: "FY Total"
  FY_CD: 2013
  Mission_Name: "RST"

etc.... through all 143 objects. 等等...通过所有143个对象。 However, the name/value pair Mission_Name:"RST" is only prevalent in the first n objects. 但是,名称/值对Mission_Name:“ RST”仅在前n个对象中普遍存在。

For example, obj 43 contains: 例如,obj 43包含:

43: Object
   ActFTEs: 0.00
   Actual: 10000
   Bud_Month: "FY Total"
   FY_CD: 2013
   Mission_Name: "VAO"

I have created the following function, but this still returns the full range of 143 values for the name/value pair related to "Bud_Month". 我创建了以下函数,但是对于与“ Bud_Month”相关的名称/值对,它仍然返回143个值的完整范围。

function get_dataArray() {
 var arr = [];
 var i= 0;
 for (i=0;i<jsonobj.row.length;i++) {   
    if (jsonobj.row[i][name]="RST") {
         arr[i] = jsonobj.row[i]["Bud_Month"];
    }    
 } 
 console.log(arr);
 return arr;
}

This returns: 返回:

["October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June"…]

Does anyone have any advice for how to return the value for "Bud_Month" only in objects containing the name/value pair of Mission_Name:"RST" ? 没有人对仅在包含Mission_Name:“ RST”的名称/值对的对象中返回“ Bud_Month”的值有任何建议吗?

if (jsonobj.row[i][name]="HST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   

Should probably be: 应该可能是:

if (jsonobj.row[i][name]=="RST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM