发布于 2017-11-29 03:02:20 | 149 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Jsonnet-PHP Jsonnet 的 PHP 扩展

JsonNet-PHP 是 Google Jsonnet 对 PHP的支持扩展.


Jsonnet-PHP v1.2.0发布了,JsonNet-PHP是Google Jsonnet对PHP的支持扩展,该版本使用最新版本至v0.9.5的LibJsonnet。

pecl:  http://pecl.php.net/package/jsonnet

github:  https://github.com/Neeke/Jsonnet-PHP

Change Log:

Fixed issue #4, pecl install failed.            
Update Lib JsonNet use v0.9.5.            
Add function JsonNet::fmtFile.            
Add function JsonNet::fmtSnippet.    

Google Jsonnet Tutorial

jsonnet语言,为我们最常使用的json对象赋予了新的生命力。使用jsonnet来描述json对象,可以在json对象中方便地使用变量引用循环等语法,甚至可以书写业务逻辑。

Install Jsonnet-PHP扩展

The pecl package is :  http://pecl.php.net/package/jsonnet    pecl install jsonnet

Input (Jsonnet)

{      cocktails: {          // Ingredient quantities are in fluid ounces.          "Tom Collins": {              ingredients: [                  { kind: "Farmers Gin", qty: 1.5 },                  { kind: "Lemon", qty: 1 },                  { kind: "Simple Syrup", qty: 0.5 },                  { kind: "Soda", qty: 2 },                  { kind: "Angostura", qty: "dash" },              ],              garnish: "Maraschino Cherry",              served: "Tall",          },          Manhattan: {              ingredients: [                  { kind: "Rye", qty: 2.5 },                  { kind: "Sweet Red Vermouth", qty: 1 },                  { kind: "Angostura", qty: "dash" },              ],              garnish: "Maraschino Cherry",              served: "Straight Up",          },      }  }

Output (JSON)

{      "cocktails": {            "Tom Collins": {              "ingredients": [                  { "kind": "Farmers Gin", "qty": 1.5 },                  { "kind": "Lemon", "qty": 1 },                  { "kind": "Simple Syrup", "qty": 0.5 },                  { "kind": "Soda", "qty": 2 },                  { "kind": "Angostura", "qty": "dash" }              ],              "garnish": "Maraschino Cherry",              "served": "Tall"          },          "Manhattan": {              "ingredients": [                  { "kind": "Rye", "qty": 2.5 },                  { "kind": "Sweet Red Vermouth", "qty": 1 },                  { "kind": "Angostura", "qty": "dash" }              ],              "garnish": "Maraschino Cherry",              "served": "Straight Up"          }      }  }

Demo of PHP

JsonNet::evaluateFile('bar_menu.1.jsonnet');        $Snippet = '      {          cocktails: {              // Ingredient quantities are in fluid ounces.              "Tom Collins": {                  ingredients: [                      { kind: "Farmers Gin", qty: 1.5 },                      { kind: "Lemon", qty: 1 },                      { kind: "Simple Syrup", qty: 0.5 },                      { kind: "Soda", qty: 2 },                      { kind: "Angostura", qty: "dash" },                  ],                  garnish: "Maraschino Cherry",                  served: "Tall",              },              Manhattan: {                  ingredients: [                      { kind: "Rye", qty: 2.5 },                      { kind: "Sweet Red Vermouth", qty: 1 },                      { kind: "Angostura", qty: "dash" },                  ],                  garnish: "Maraschino Cherry",                  served: "Straight Up",              },          }      }      ';        var_dump(JsonNet::evaluateSnippet($Snippet));


历史版本 :
Jsonnet-PHP v1.2.0 发布, PHP 支持 Jsonnet 扩展
Jsonnet-PHP v1.1.0 发布, PHP 的支持扩展
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务