在Json中创建多个子项

时间:2014-05-28 16:27:17

标签: arrays json

对于json来说,我是一个新手,所以需要一点帮助 当我第一次得到我们的数据库时,它工作得很好

{    
   "Audi":[
      "80",
      "100",
   ],
   "Bentley":[
      "Azure",
      "(C)",
   ]
}

现在我们想把它扩展一点,所以它更像下面但是它显然是错的?

    { "Audi": [
    “50”:[
    “50 L(1974-1978)”:["Alternators","Starter Motors"]],
    “50 GL(1974-1978)”:["Alternators","Starter Motors"]],
    “A1”:[
    “A1 1.2 TFSI(2010-)”:["Alternators","Starter Motors"]],
    “A1 1.4 TFSI(2010-)”:["Alternators","Starter Motors"]],
    }

所以层次结构更像是= make / model /"模型引擎和年份" /然后是产品类别。希望这有意义

2 个答案:

答案 0 :(得分:0)

你很亲密

{
    "Audi": {
        "50": { "50 L(1974-1978)": ["Alternators", "Starter Motors"],
                "50GL(1974-1978)": ["Alternators", "Starter Motors"] },
        "A1": { "A11.2TFSI(2010-)": ["Alternators", "Starter Motors"],
                "A11.4TFSI(2010-)": ["Alternators", "Starter Motors"] }
    }
}

答案 1 :(得分:-1)

谢谢大家我已经解决了它现在工作正常。我使用了一个非常有用的编辑器和验证器,可以在这里找到.. http://www.jsoneditoronline.org/
以下是有效的版本。

{
    "Audi":{
    "50": {
        "50 L(1974-1978)": ["Alternators", "Starter Motors"], 
        "50GL(1974-1978)": ["Alternators", "Starter Motors"] }, 
        "A1": {
        "A1 1.2TFSI(2010-)": ["Alternators", "Starter Motors"], 
        "A1 1.4TFSI(2010-)": ["Alternators", "Starter Motors"], 
        "A1 Sportback 1.6 TDI(2010-)":["Alternators","Starter Motors"], 
        "A1 Sportback 2.0 TDI(2011-)":["Alternators","Starter Motors"] }
        },
 "Audiv2":{
    "50": {
        "50 L(1974-1978)": ["Alternators", "Starter Motors"], 
        "50GL(1974-1978)": ["Alternators", "Starter Motors"] }, 
    "A1": {
        "A1 1.2TFSI(2010-)": ["Alternators", "Starter Motors"], 
        "A1 1.4TFSI(2010-)": ["Alternators", "Starter Motors"],  
        "A1 Sportback 2.0 TDI(2011-)":["Alternators","Starter Motors"] }}

}