| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

JSON文档映射成对象的PHP库:cartographer

这是一个超级简单的PHP库用于将JSON文档映射成对象,类似于Java的 Jackson。
// Create a new instance of the Mapper  $mapper = new \Xenolope\Cartographer\Mapper();    // Map a JSON string to a POPO    // PHP 5.4  $object = $mapper->mapString(      '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',      'Vendor\Package\Entity\Contact'  );    // PHP >=5.5  $object = $mapper->mapString(      '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',      Contact::class  );    // Map an already decoded (to array) JSON document to a POPO    // This might happen automatically in your Request class, for example  $jsonDocument = json_decode(      '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',      true  );    // PHP 5.4  $object = $mapper->map($jsonDocument, 'Vendor\Package\Entity\Contact');    // PHP >= 5.5  $object = $mapper->map(      '{"name":"Liz Lemon","address":{"street":"168 Riverside Dr.","city":"New York"}}',      Contact::class  );

项目主页:http://www.open-open.com/lib/view/home/1419339290437

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1419339290437.html
JSON开发包 cartographer