奇怪的json语法

时间:2013-01-30 20:31:43

标签: jquery html json

我有一个关于json输出和jquery的问题。 这是json数据,但语法非常奇怪:

{"ResC": {
"@attributes": {
  "ver": "1.1",
  "prod": "HAFAS 5.31.VBB.4.8.9",
  "lang": "DE"
},
"STBRes": {
  "@attributes": {"plan_version": "planid=1358257894-planid_adr=1336152870-planid_poi=1357822240-planid_ext=1343914901"},
  "JourneyList": {"STBJourney": [
      {
        "@attributes": {"trainId": "1628608644#30.01.13"},
        "MainStop": {"BasicStop": {
            "@attributes": {"index": "4"},
            "Station": {"@attributes": {
                "name": "S+U Westhafen (Berlin)",
                "x": "13342724",
                "y": "52536529",
                "type": "WGS84",
                "externalId": "9001201#86",
                "externalStationNr": "9001201"
              }},
            "Dep": {"Time": "30.01.13T21:26"}
          }},
        "JourneyAttributeList": {"JourneyAttribute": [
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "NAME"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "U9"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {
                  "type": "CATEGORY",
                  "code": "1"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "U"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "INTERNALCATEGORY"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "U"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "OPERATOR"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "BVG"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "NUMBER"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "U9"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTION"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S+U Rathaus Steglitz (Berlin)"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONFLAG"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "1"
                }
              }
            },
            {
              "@attributes": {
                "from": "4",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONCODE"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "9062202"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "350",
                  "type": "NORMAL",
                  "code": "RA"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "Fahrradmitnahme möglich"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "17"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "1",
                  "type": "NORMAL",
                  "code": "bf"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "barrierefrei"
                }
              }
            }
          ]},
        "ServiceDaysList": {"ServiceDays": {
            "ServiceBits": "FFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "RegularServiceText": {"Text": "täglich"},
            "IrregularServiceText": {"Text": "nicht 30. Mär"}
          }}
      },
      {
        "@attributes": {
          "trainId": "3599408640#30.01.13",
          "journeyId": "42221"
        },
        "MainStop": {"BasicStop": {
            "@attributes": {"index": "15"},
            "Station": {"@attributes": {
                "name": "S+U Westhafen (Berlin)",
                "x": "13342724",
                "y": "52536529",
                "type": "WGS84",
                "externalId": "9001201#86",
                "externalStationNr": "9001201"
              }},
            "Dep": {
              "Time": "30.01.13T21:27",
              "Platform": {"Text": "2"}
            },
            "StopPrognosis": {"Dep": {
                "Time": "30.01.13T21:27",
                "Platform": {"Text": "2"}
              }}
          }},
        "JourneyAttributeList": {"JourneyAttribute": [
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "NAME"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S42"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "type": "CATEGORY",
                  "code": "0"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "INTERNALCATEGORY"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S-6"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "OPERATOR"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "DBS"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "NUMBER"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S42"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTION"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "Ringbahn S 42"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONFLAG"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "2"
                }
              }
            },
            {
              "@attributes": {
                "from": "15",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONCODE"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "R000498"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "350",
                  "type": "NORMAL",
                  "code": "FB"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "Fahrradmitnahme möglich"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "1",
                  "type": "NORMAL",
                  "code": "ck"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "barrierefrei"
                }
              }
            }
          ]},
        "ServiceDaysList": {"ServiceDays": {
            "ServiceBits": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "RegularServiceText": {"Text": "täglich"}
          }}
      },
      {
        "@attributes": {
          "trainId": "3599408634#30.01.13",
          "journeyId": "42221"
        },
        "MainStop": {"BasicStop": {
            "@attributes": {"index": "42"},
            "Station": {"@attributes": {
                "name": "S+U Westhafen (Berlin)",
                "x": "13342724",
                "y": "52536529",
                "type": "WGS84",
                "externalId": "9001201#86",
                "externalStationNr": "9001201"
              }},
            "Dep": {
              "Time": "30.01.13T21:27",
              "Platform": {"Text": "2"}
            },
            "StopPrognosis": {"Dep": {
                "Time": "30.01.13T21:27",
                "Platform": {"Text": "2"}
              }}
          }},
        "JourneyAttributeList": {"JourneyAttribute": [
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "NAME"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S42"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "type": "CATEGORY",
                  "code": "0"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "INTERNALCATEGORY"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S-6"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "OPERATOR"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "DBS"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "NUMBER"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "S42"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTION"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "Ringbahn S 42"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONFLAG"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "2"
                }
              }
            },
            {
              "@attributes": {
                "from": "42",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {"type": "DIRECTIONCODE"},
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "R000498"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "350",
                  "type": "NORMAL",
                  "code": "FB"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "Fahrradmitnahme möglich"
                }
              }
            },
            {
              "@attributes": {
                "from": "0",
                "to": "54"
              },
              "Attribute": {
                "@attributes": {
                  "priority": "1",
                  "type": "NORMAL",
                  "code": "ck"
                },
                "AttributeVariant": {
                  "@attributes": {"type": "NORMAL"},
                  "Text": "barrierefrei"
                }
              }
            }
          ]},
        "ServiceDaysList": {"ServiceDays": {
            "ServiceBits": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "RegularServiceText": {"Text": "täglich"}
          }}
      }
    ]}
}
}}

有一些条目被声明为属性和类型。如何查询类型为DIRECTION的条目的文本?

1 个答案:

答案 0 :(得分:1)

这种语法没什么奇怪的,普通的JSON:

data["ResC"]["@attributes"]["ver"] // "1.1"

它是根据某些XML生成的,因此属性名称如"@attributes"