红联Linux门户
Linux帮助

Jsonnet-PHP v1.1.0发布,PHP的支持扩展

发布时间:2016-07-14 22:34:11来源:红联作者:baihuo
Jsonnet-PHP v1.1.0 发布了,JsonNet-PHP 是 Google Jsonnet 对 PHP的支持扩展,v1.1.0,使用最新版本至v0.8.9的LibJsonnet。

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

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

Change Log:

- Update Lib JsonNet use v0.8.9.
- Fixed issue #1 #2, install error and .so load failed.

Google Jsonnet Tutorial

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

Install Jsonnet-PHP扩展[code]The pecl package is : http://pecl.php.net/package/jsonnet
pecl install jsonnet
Input (Jsonnet)[/code][code]{
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",
},
}
}[/code]Output (JSON)[code]{
"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"
}
}
}[/code]Demo of PHP[code]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));[/code]软件详情:https://github.com/Neeke/Jsonnet-PHP

下载地址:http://pecl.php.net/package/jsonnet

来自:开源中国社区
文章评论

共有 0 条评论