json-schema-php
- 授权协议: GPL
- 开发语言: PHP
- 操作系统: 跨平台
- 软件首页: http://code.google.com/p/json-schema-php/
- 软件文档: http://code.google.com/p/json-schema-php/
软件介绍
JSON Schema 用于描述JSON数据的结构和类型。如同DTD与XML的关系。
本实现用于使用 PHP 调用 JSON Schema 对 JSON 数据进行验证。
生成 JSON Schema
由JSON生成一个全格式的Schema,方便编辑修改(勿随便直接使用在实践中)。
$value = new stdClass(); $value->name = 'a name'; $value->age = 23; $value->height = 183.5; $jsonSchema = new JsonSchema(json_encode($value)); echo $jsonSchema->getSchema();
结果(真实结果格式化后)
{
"type":"object",
"properties":{
"name":{
"type":"string",
"format":"regex",
"pattern":"\/^[a-z0-9]+$\/i",
"minLength":0,
"maxLength":2147483647
},
"age":{
"type":"integer",
"default":0,
"minimum":0,
"maximum":2147483647,
"exclusiveMinimum":0,
"exclusiveMaximum":2147483647
},
"height":{
"type":"number",
"default":0,
"minimum":0,
"maximum":2147483647,
"exclusiveMinimum":0,
"exclusiveMaximum":2147483647
}
}
}
使用 JSON Schema 验证 JSON
$userType = '
{
"id": "user",
"description": "user info",
"type": "object",
"properties": {
"account": {"type": "string"},
"email": {"type": "string", "required": true},
"noexist": {"type": "string", "required": false}
}
}';
$type = array();
$type['users'][] = array('account' => 'userA', 'email' => 'userA@example.com');
$type['users'][] = array('account' => 'userB', 'email' => 'userB@example.com');
$type['users'][] = array('account' => 'userC', 'email' => 'userC@example.com');
$jsonSchema = new JsonSchema(json_encode($type));
$jsonSchema->addTypes($userType);
$jsonSchema->validate('
{
"type":"object",
"properties":{
"users":{
"type":"array",
"items":{
"$ref":"user"
}
}
}
}');
深度探索C++对象模型(影印版)
Stanley B. Lippman / 中国电力出版社 / 2003-8-1 / 42.00
本书重点介绍了C++面向对象程序设计的底层机制,包括结构式语意、暂时性对象的生成、封装、继承和虚拟——虚拟函数和虚拟继承。书中向你表明:理解底层实现模型,可以极大地提高你的编码效率。Lippman澄清了那些关于C++系统开销与复杂性的各种错误信息和猜测,指出了其中某些成本和利益交换确实存在。他在书中详述了各种实现模型,指出了它们的发展方向以及促使其发展的根本原因。本书涵盖了C++对象模型的语意暗示......一起来看看 《深度探索C++对象模型(影印版)》 这本书的介绍吧!
