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扩展

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

Input (Jsonnet)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
    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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
    "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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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));
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()