1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

新闻 支持 JsonNet 的 PHP 扩展发布 下载

本帖由 漂亮的石头2015-06-01 发布。版面名称:软件资讯

  1. 漂亮的石头

    漂亮的石头 版主 管理成员

    注册:
    2012-02-10
    帖子:
    486,336
    赞:
    46
    JsonNet-PHP 是 Google Jsonnet 对 PHP的支持扩展.

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

    gitosc: http://git.oschina.net/ciogao/JsonNet

    github: https://github.com/Neeke/JsonNet

    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 扩展发布下载地址
     
正在加载...