可以从Javascript访问JSON属性

可以从Javascript访问JSON属性,javascript,json,Javascript,Json,我的json: { locale: "en", title: "Survey", focusFirstQuestionAutomatic: false, pages: [ { name: "livingEnvironment", elements: [ { type: "html", name: "navigationWarning", html: "To navigate " },

我的json:

     {
  locale: "en",
  title: "Survey",
  focusFirstQuestionAutomatic: false,
  pages: [
   {
    name: "livingEnvironment",
    elements: [
     {
      type: "html",
      name: "navigationWarning",
      html: "To navigate "
     },
     {
      type: "html",
      name: "IntroEnvironment",
      html: "We will now ask you questions about your living environment"
     },
     {
      type: "text",
      name: "numhousehold",
      width: "auto",
      title: "How many people (including yourself) lived in your household",
      validators: [
       {
        type: "numeric",
        text: "Please enter a number between 1 and 99.",
        minValue: 1,
        maxValue: 99
       }
      ],
      inputType: "number"
     },
     {
      type: "multipletext",
      name: "householdtype",
      width: "auto",
      title: "Of these, how many (including yourself) were:",
      items: [
       {
        name: "children",
        inputType: "number",
        title: "Children under 18 years old",
        validators: [
         {
          type: "regex",
          text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
          regex: "^(\\s*|\\d+)$"
         }
        ]
       },
       {
        name: "adults",
        inputType: "number",
        title: "Adults between 18-59 years old",
        validators: [
         {
          type: "regex",
          text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
          regex: "^(\\s*|\\d+)$"
         }
        ]
       },
       {
        name: "seniors",
        inputType: "number",
        title: "Seniors (60+)",
        validators: [
         {
          type: "regex",
          text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
          regex: "^(\\s*|\\d+)$"
         }
        ]
       },
       {
        name: "disabled",
        inputType: "number",
        title: "Disabled",
        validators: [
         {
          type: "regex",
          text: "One of the numbers below is out of range. Please enter 0, a positive number, or leave the box blank.",
          regex: "^(\\s*|\\d+)$"
         }
        ]

      }
   }
 ]}
我的javascript是:

function serverValidateQuestion(survey, options) {
            console.log('Validation called');
            console.log(options.data.householdtype);
            console.log(options.data.householdtype.children);
因此,我可以访问
console.log(options.data.householdtype)
,它会给我家庭类型中的项目列表。但是,我尝试从householdtype访问“children”值输入。当我编写console.log(options.data.householdtype.children)时,它会给我

`
无法读取“未定义”错误的属性。在谷歌控制台模式下, “console.log(options.data.householdtype)”提供了以下信息:

`“成年人 : "3" 儿童 : "3" 残废 : "3" 怀孕的 : "3" 老年人 : "3" proto : 反对


但是我只想访问children值和
console.log(options.data.householdtype.children)
不起作用。另外,
console.log(options.data.numhousehold)
确实给了我一个用户输入的值。此外,这些值来自用户在调查期间填写的输入框。请帮帮我。

好吧,我想这是因为html文件console.log(options.data.householdtype)的第一页上的;未定义。在我的html的第二页上,它是否找到了householdtype,然后可以访问console.log(options.data.householdtype.children);否则它不工作。

我在JSON中的任何地方都没有看到
householdtype
属性。我看到
名称:“householdtype”
name:“children
,但这些是值,而不是属性名。json没有匹配的括号。当您使用
选项时,这不能是您正在引用的对象。data.householdtype
。请编辑并格式化您的文章,这是不可读的。@Barmar我的意思是访问值名:“children”