Javascript对象获取属性(数组)

时间:2015-10-26 19:04:33

标签: javascript json object

我在Javascript中有一个Json对象,看起来像这样:

function onSubmit(e) {
  //Open Marketing - Discoveries and Changes - v1
  var sheet = e.range.getSheet();

  //Return Spreadsheet that contains this sheet
  var ss = sheet.getParent();

  //Open Marketing - Discoveries and Changes - v1
  var form = FormApp.openById(ss.getFormUrl());

  //Destination sheet based on "Location of Change"
  var destSheet = getSheet(ss, e.namedValue['Location of Change']);

  //Store response in destination sheet
  destSheet.appendRow(e.values);

  function getSheet( spreadsheet, sheetName, headings) {
    spreadsheet = SpreadsheetApp.getActive();
    var sheet = spreadsheet.getSheetByName(sheetName);
    if (sheet == null) {
      sheet = spreadsheet.insertSheet(sheetName);
      if (headings && headings.constructor === Array) {
        sheet.getRange(1,1,1, headings.length).setValues([headings]);
      }
    }
    return sheet;
  }

}

我想要的只是“项目”部分。看起来像这样:

{
"properties": {
    "processowner" : { "valueType": "text" },
    "withwhat" : { "valueType": "text" },
    "withwho" : { "valueType": "text" },
    "processstep" : { "valueType": "text" },
    "cluster" : { "valueType": "text" }
},
"items": [
    {
        "label": "anytitle",
        "processowner": ["Name"],
        "withwhat": ["ben\u00f6tigtes Material","ben\u00f6tigtes Material2","ben\u00f6tigtes Material3"],
        "withwho": ["Verantwortliche Person"],
        "processstep": ["1. Schritt 1","2. Schritt 2","3. Schritt 3","4. Schritt 4","5. Schritt 5"],
        "cluster": ["anyname"]
    },
    {
        "label": "anytitle",
        "processowner": ["Name"],
        "withwhat": ["ben\u00f6tigtes Material","ben\u00f6tigtes Material2","ben\u00f6tigtes Material3"],
        "withwho": ["Verantwortliche Person"],
        "processstep": ["1. Schritt 1","2. Schritt 2","3. Schritt 3","4. Schritt 4","5. Schritt 5"],
        "cluster": ["anyname"]
    },
........
}

我试图用它来访问它     objectname.items 但是当我在控制台上打印时,我总是得到“未定义”。

编辑:

[
    {
        "label": "anytitle",
        "processowner": ["Name"],
        "withwhat": ["ben\u00f6tigtes Material","ben\u00f6tigtes Material2","ben\u00f6tigtes Material3"],
        "withwho": ["Verantwortliche Person"],
        "processstep": ["1. Schritt 1","2. Schritt 2","3. Schritt 3","4. Schritt 4","5. Schritt 5"],
        "cluster": ["anyname"]
    },
    {
        "label": "anytitle",
        "processowner": ["Name"],
        "withwhat": ["ben\u00f6tigtes Material","ben\u00f6tigtes Material2","ben\u00f6tigtes Material3"],
        "withwho": ["Verantwortliche Person"],
        "processstep": ["1. Schritt 1","2. Schritt 2","3. Schritt 3","4. Schritt 4","5. Schritt 5"],
        "cluster": ["anyname"]
    },
........
]

}

0 个答案:

没有答案