sgmendez/jsonbundle

Symfony2 用于json编码和解码的扩展包

v1.0.2 2015-03-24 00:28 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:48:22 UTC


README

License SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version

Json 集成 Symfony2 扩展包。

安装

您可以使用 Composer 在您的应用程序中使用此库。

如果您还没有 Composer,请按照http://getcomposer.org/上的说明下载,或者直接运行以下命令

curl -s http://getcomposer.org/installer | php

然后执行以下命令将库添加到您的项目中

$ composer require sgmendez/jsonbundle

或者在您的 composer.json 文件中 require sgmendez/json

json
{
    "require": {
        "sgmendez/jsonbundle": "*"
    }
}

在 appKernel 上注册扩展包

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Sgmendez\Bundle\JsonBundle\JsonBundle(),
        // ...
    );
}

使用方法

对于字符串 JSON 数据

php

$json = $this->get('json.parser');
$a = $json->decode($stringJson);

对于本地文件 JSON 数据

php

$json = $this->get('json.parser');
$a = $json->decodeFile('file.json');

对于远程文件 JSON 数据

php

$json = $this->get('json.parser');
$a = $json->decodeFile('http://ip.jsontest.com/');

许可证

在 BSD 许可证下授权

https://open-source.org.cn/licenses/bsd-license.php