赞
踩
-
- {
- "$schema": "http://json-schema.org/draft-03/schema#",
- "title": "App",
- "description": "APP LIST",
- "type": "array",
- "properties":{
- "appID": {
- "type": "string",
- "required":true
- },
- "appName":{
- "type": "string",
- "required":true
- },
- "appCaption":{
- "type": "string",
- "required":true
- },
- "icon":{
- "type":"string",
- "required":true
- }
- }
- }
-
- [{"appID":"1","appName":"push","appCaption":"push ","icon":""},{"appID":"52","appName":"Sample(\u4e13\u7528)","appCaption":"Sample(\u4e13\u7528)","icon":""},{"appID":"64","appName":"\u65b0\u73af\u5883\u6d4b\u8bd5dddd","appCaption":"\u65b0\u73af\u5883\u6d4b\u8bd5","icon":""}]
-
-
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="chrome=1" />
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>dojox.json.schema example</title>
-
- <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.0/dojo/dojo.js"
- type="text/javascript"></script>
-
- <script type="text/javascript">
-
- require(["dojox/json/schema"], function() {
- // Object to validate
- var successObj = {
- "foo" : "bar"
- };
- var failureObj = {
- "foo" : 1234
- };
-
- // Schema
- var schema = {
- "type": "object",
- "properties" : {
- "foo" : {
- "type" : "string"
- },
- "icon":{
-
- }
- }
- };
-
- // Run validation, which should succeed
- // Change this line to use failureObj to see the failure case
- var result = dojox.json.schema.validate(successObj, schema);
-
- // Check results
- if (result.valid) {
- // Success, do something
- alert("Object is valid");
- } else {
- // Failure - extract the errors array
- var errorArr = result.errors;
- alert("property : " + errorArr[0].property + "\nmessage : "
- + errorArr[0].message);
- }
- });
-
- </script>
-
-
- </head>
-
- <body>
- <h1>Example use of dojox.json.schema</h1>
- <p>
- Due to its use of the Dojo CDN distribution on google.com, this HTML file MUST be accessed through an HTTP server such as Apache. file:/// URIs won't work.'
- </p>
- </body>
-
- </html>
-
- tests["Status code is 200"] = responseCode.code === 200;
-
- var data = JSON.parse(responseBody);
- tests["status"] = data.status === true;
- tests["info"] = data.info === "success";
- var appData = data.data;
- tests['appCount'] = appData.length === 3;
- var schema = {
- "$schema": "http://json-schema.org/draft-04/schema#",
- "title": "App",
- "description": "APP LIST",
- "type": "object",
- "properties":{
- "appID": {
- "type": "string"
- },
- "appName":{
- "type": "string"
- },
- "appCaption":{
- "type": "string"
- },
- "icon":{
- "type":"string",
- "required":true,
- "pattern":"^http://"
- }
- }
- };
-
- $.each(appData, function (i) {
- var app = this;
- tests['appName'+i] = tv4.validate(app, schema);
- })
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。