2013-08-06 8 views
5

मैं जेएसओएन स्कीमा का वर्णन करके एचटीएमएल फॉर्म से इनपुट को प्रमाणित करना चाहता हूं। मैं इसे सत्यापित करने के लिए गैरी कोर्ट के जेएसवी का उपयोग कर रहा हूं और यह लगातार एक त्रुटि देता है। मैंने अपनी स्कीमा की जांच के लिए JSON स्कीमा लिंट (jsonschemalint.com) का उपयोग किया। क्रोम स्कीमा लिंट में मुझे बताता है कि मेरी स्कीमा मान्य है, लेकिन फ़ायरफ़ॉक्स में, सफारी & ओपेरा वेबसाइट मुझे बताती है कि मेरी स्कीमा वैध JSON है लेकिन वैध JSON स्कीमा नहीं है। क्या कोई मेरी मदद कर सकता है। मेरी स्कीमा नीचे है।JSON स्कीमा का उपयोग कर फ़ॉर्म को कैसे सत्यापित करें?

अद्यतन 8/6/13 आपके सभी उत्तरों के लिए धन्यवाद। मेरा अद्यतन JSON (नीचे अपडेट किया गया) अब सभी ब्राउज़रों में मान्य है। हालांकि मैं अभी भी 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 

मुझे पहले का कहना है कि मैं त्रुटि संदेश गलत तरीके से व्याख्या की जा सकती है करते हैं। हालांकि मैं काफी हद तक निश्चित हूं कि यह उद्घाटन घुंघराले ब्रैकेट के बाद सीधे "type": "object" लाइन का जिक्र कर रहा है। हालांकि "type": "object" कुंजी: मान http://tools.ietf.org/html/draft-zyp-json-schema-03 पर ड्राफ्ट 03 spec का हिस्सा है। यह भ्रमित है क्योंकि जेएसओएन स्कीमा लिंट जेएसवी लाइब्रेरी का भी उपयोग करता है ... अब तक आपकी सभी मदद के लिए धन्यवाद।

{ 
"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 
    } 
} 
} 
+0

क्या यह "आवश्यक" हो सकता है शुरुआत के दौरान केवल 'सत्य' या 'झूठा' हो सकता है? आप इसे कई गैर-बुलियन मूल्यों पर सेट कर चुके हैं। –

+0

इसे भी आजमाएं: http://jsonlint.com/ –

उत्तर

4

मैं the JSON schema website में फिर से जाँच की और ऐसा लगता है नाम "Turbidity (ntu)" किसी मान्य कुंजी नहीं है। JSON schema कुंजी में कोष्ठक पसंद नहीं करता है। यह काम करता है अगर आप "Turbidity ntu" में ब्रांड्स को छोड़ देते हैं।

मैं स्पष्ट रूप से इसे वापस ले जाने पर @ pmagunia की प्रविष्टि पर टिप्पणी कर रहा था। उन्होंने टिप्पणी की कि required में केवल बूलियन मान हो सकते हैं। मुझे ऐसा लगता है कि शीर्ष पर required संपत्ति वास्तव में अनिवार्य है। मैंने अभी इसे JSON Schema Lint में परीक्षण किया है और स्कीमा को इसके बिना मान्य माना जाता है। लेकिन required निश्चित रूप से केवल हो सकता है बूलियन मान रखें। आपका सरणी

[ "TestSite", "Date of Test", "Latitude", "Longitude" ] 

एक गैर उद्धृत स्ट्रिंग

TestSite,Date of Test,Latitude,Longitude 

जो निश्चित रूप से अमान्य JSON हो जाएगा में JSON स्कीमा एक प्रकार का वृक्ष से बदल गया था!

+0

नहीं, वह नहीं था। बस फिर से जांच की। इस बार सभी कोष्ठक स्वीकार किए गए थे। अजीब। क्षमा करें ... – cars10m

+0

कार 10 सही है; आवश्यक गुणों की सरणी केवल जेसन-स्कीमा के v4 ड्राफ्ट में मान्य है और इसलिए इसे हटाया जाना चाहिए क्योंकि आप v3 ड्राफ्ट का उपयोग कर रहे हैं। –

2

आपके जेसन के पास चाबियाँ हैं। Air Temperature (C) की तरह। कोष्ठक भी हटा दें। यदि आप अपनी चाबियों से सफेद जगहों को हटा देंगे तो यह वैध स्कीमा होगा।

संबंधित मुद्दे