json 嵌套在对象Array中的对象Array

ryevplcw  于 2022-12-05  发布在  其他
关注(0)|答案(2)|浏览(149)

在JSON中表示此结构的正确方式是什么
它的字符串数组,带有标识符(A是标识符,Printer是数组项)
然后是字符串的嵌套列表,带有标识符

A Printer   
    A0010 Not printing
    A0020 Out of ink
    A0030 No power
    A0040 Noise
    A0300 Feedback
    A0500 Other
B PC Issues
    B0010 No power
    B0020 BSOD
    B0030 Virus related
    B0300 Feedback
    B0500 Other

谢谢你的帮忙

9nvpjoqh

9nvpjoqh1#

这是否能让您轻松过滤内容?
可以使用Object.keys查找相应的消息

const json = {
  data: [{
      identifier: 'A',
      itemType: 'Printer',
      error: [
        {
          'A0010': 'Not printing'
        },
        {
          'A0020': 'Out of ink'
        },
        {
          'A0030': 'No power',
        },
        {
          'A0040': 'Noise',
        },
        {
          'A0300': 'Feedback',
        },
        {
          'A0500': 'Other'
        }

      ]
    },
    {
      identifier: 'B',
      itemType: 'PC Issues',
      error: [
        {
          'B0010': 'No power'
        },
        {
          'B0020': 'BSOD',
        },
        {
          'B0030': 'Virus related'
        }, {
          'B0300': 'Feedback'
        },
        {
          'B0500': 'Other'
        },
      ]
    }
  ]
}
eufgjt7s

eufgjt7s2#

我不太清楚标识符是什么意思,除非你是指通过javascript👇

var a = {
    "Printer":[    
    {
    "identifier" : "A0010",
    "reason" : "Not printing"
    },    
    {
    "identifier" : "A0020",
    "reason" : "Out of ink"
    },
    {
    "identifier" : "A0030",
    "reason" : "No power"
    },
    {
    "identifier" : "A0040",
    "reason" : "Noise"
    },
    {
    "identifier" : "A0300",
    "reason" : "Feedback"
    },
    {
    "identifier" : "A0500",
    "reason" : "Other"
    }]
}
var b = {
    "PC Issues":[    
    {
    "identifier" : "B0010",
    "reason" : "No power"
    },    
    {
    "identifier" : "B0020",
    "reason" : "BSOD"
    },
    {
    "identifier" : "B0030",
    "reason" : "Virus related"
    },
    {
    "identifier" : "B0300",
    "reason" : "Feedback"
    },
    {
    "identifier" : "B0500",
    "reason" : "Other"
    }]
}

相关问题