Tôi muốn xác thực đầu vào từ một biểu mẫu HTML bằng cách sử dụng Lược đồ JSON mô tả nó. Tôi đang sử dụng JSV của Gary Court để xác thực nó và nó trả về một lỗi nhất quán. Tôi đã sử dụng lược đồ JSON Lint (jsonschemalint.com) để kiểm tra lược đồ của tôi. Trong Lược đồ Chrome Lint cho tôi biết lược đồ của tôi là hợp lệ, nhưng trong Firefox, Safari & Opera trang web cho tôi biết rằng lược đồ của tôi là JSON hợp lệ nhưng không phải là lược đồ JSON hợp lệ. Bất cứ ai có thể giúp tôi ra ngoài. Sơ đồ của tôi ở bên dưới.Làm cách nào để xác thực biểu mẫu bằng JSON Schema?
CẬP NHẬT 8/6/13 Cảm ơn tất cả các thư trả lời của bạn. JSON cập nhật của tôi (được cập nhật bên dưới) hiện đang xác thực trong tất cả các trình duyệt. Tuy nhiên, tôi vẫn nhận được lỗi sau từ JSV:
Report {errors: Array[1], validated: Object, instance: JSONInstance, schema: JSONSchema, schemaSchema: JSONSchema…}
errors: Array[1]
0: Object
attribute: "type"
details: Array[1]
0: "object"
length: 1
__proto__: Array[0]
message: "Instance is not a required type"
schemaUri: "http://json-schema.org/draft-03/hyper-schema#"
uri: "urn:uuid:808fe74b-b0d0-4774-8975-289f105dfeaa#"
__proto__: Object
length: 1
__proto__: Array[0]
instance: JSONInstance
schema: JSONSchema
schemaSchema: JSONSchema
validated: Object
__proto__: Report
Hãy để tôi nói rằng tôi có thể diễn giải thông báo lỗi không chính xác. Tuy nhiên tôi khá chắc chắn điều này là đề cập đến các dòng "type": "object"
trực tiếp sau khi mở dấu ngoặc nhọn. Tuy nhiên, khóa "type": "object"
: giá trị là một phần của thông số Draft 03 tại http://tools.ietf.org/html/draft-zyp-json-schema-03. Điều này là khó hiểu vì JSON Schema Lint cũng sử dụng thư viện JSV ... Cảm ơn tất cả sự giúp đỡ của bạn cho đến nay.
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema#",
"title": "FormValidation",
"description": "Describes the types of and valid inputs to a form generated via Form Creator",
"properties": {
"Air Temperature (C)": {
"type": "number",
"description": "Air Temperature measurement in centigrade.",
"required": false
},
"Ammonia": {
"type": "number",
"description": "Ammonia measurement at test site.",
"required": false
},
"Aquatic Life Present": {
"type": "string",
"description": "Are organisms such as fish or frogs living near the test site?",
"required": false
},
"Chlorophyll a": {
"type": "number",
"description": "Chlorophyll a measurement at test site.",
"required": false
},
"Conductivity": {
"type": "number",
"description": "Water conductivity measurement at test site.",
"required": false
},
"Date of Test": {
"type": "string",
"description": "Date the measurements were recorded.",
"required": true
},
"Dissolved Oxygen 1": {
"type": "number",
"description": "Disolved oxygen reading at first depth.",
"required": false
},
"Dissolved Oxygen 2": {
"type": "number",
"description": "Dissolved oxygen reading at second depth.",
"required": false
},
"Latitude": {
"type": "number",
"description": "Latitude of the measurement site in degrees.",
"required": true
},
"Longitude": {
"type": "number",
"description": "Longitude of the measurement site in degrees.",
"required": true
},
"Nitrates": {
"type": "number",
"description": "Nitrate measurement at test site.",
"required": false
},
"Orthophosphates": {
"type": "number",
"description": "Orthophosphate measurement at site of testing.",
"required": false
},
"Phosphates": {
"type": "number",
"description": "Phosphate reading at measurement site.",
"required": false
},
"Secchi Disk": {
"type": "number",
"description": "Secchi Disk depth reading at measurement site.",
"required": false
},
"Site Change": {
"type": "string",
"description": "Has the site undergone noticeable physical change since the last measuring event?",
"required": false
},
"Test Site": {
"type": "string",
"description": "Location where the measurements were recorded.",
"required": true
},
"Turbidity (ntu)": {
"type": "number",
"description": "Cloudiness or haziness of water, measured in Nephelometric Turbidity Units (NTU).",
"required": false
},
"Water Color or Odor": {
"type": "string",
"description": "Does the water have an strange colorations or emit a noticeable odor?",
"required": false
},
"Water Temperature (C)": {
"type": "number",
"description": "Water Temperature measurement in centigrade.",
"required": false
},
"pH": {
"type": "number",
"description": "pH measurement at test site.",
"required": false
}
}
}
có thể là "bắt buộc" chỉ có thể là 'đúng' hoặc 'sai' gần đầu? bạn đã đặt nó thành một số giá trị không boolean. –
Hãy thử cái này cũng: http://jsonlint.com/ –