1

如何通过 json 模式表达这个 XML?

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

谢谢你!

4

1 回答 1

1

我认为这就是你想要的:

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

另外,让我告诉你一个小秘密;)

现在,对于 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"}
        }
        }
    }
    }
}
}

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

于 2013-04-23T04:36:21.130 回答