企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] > [github](https://github.com/cweiske/jsonmapper) ## 安装 `composer require netresearch/jsonmapper` ## 使用 ``` $json='{"name":"Sheldon Cooper","address":{"street":"2311 N. Los Robles Avenue","city":"Pasadena"}}'; class Contact { /** * Full name * @var string */ public $name; /** * @var Address */ public $address; } class Address { public $street; public $city; public function getGeoCoords() { echo "hello word:===".$this->city."==="; } } $mapper = new JsonMapper(); $contact = $mapper->map(json_decode($json), new Contact()); $contact->address->getGeoCoords();//hello word:===Pasadena=== ```