如何通过json架构表达这个XML?

时间:2013-04-23 04:17:54

标签: xml jsonschema

如何通过json架构表达这个XML?

<students>
    <student name="jack">
        <age>23</age>
        <address>
            <city>new town</city>
            <street>my home street 105.</street>
        </address>
    </student>
</students>
谢谢你!

1 个答案:

答案 0 :(得分:1)

我认为这就是你想要的:

{
  "students": {
    "student": {
      "-name": "jack",
      "age": "23",
      "address": {
        "city": "new town",
        "street": "my home street 105."
      }
    }
  }
}

另外,让我告诉你一个 little secret ;)

现在,对于json架构:

"$schema": "http://json-schema.org/draft-03/schema", "id": "http://jsonschema.net", "required": false, "type": "object", "properties":{
  [-]"students":{
      "id": "http://jsonschema.net/students", "required": false, "type": "object", "properties":{
      [-]"student":{
          "id": "http://jsonschema.net/students/student", "required": false, "type": "object", "properties":{
          [-]"-name":{
          "id": "http://jsonschema.net/students/student/-name", "required": false, "default": "jack", "type":"string"}
          ,[-]"address":{
              "id": "http://jsonschema.net/students/student/address", "required": false, "type": "object", "properties":{
              [-]"city":{
              "id": "http://jsonschema.net/students/student/address/city", "required": false, "default": "new town", "type":"string"}
              ,[-]"street":{
              "id": "http://jsonschema.net/students/student/address/street", "required": false, "default": "my home street 105.", "type":"string"}
            }
            }
          ,[-]"age":{
          "id": "http://jsonschema.net/students/student/age", "required": false, "default": "23", "type":"string"}
        }
        }
    }
    }
}
}

对不起,我在这里使用有限的工具。 现在是 secret #2