sobernt/jq-object

安装: 6

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:项目

1.0.0 2019-11-20 03:26 UTC

This package is auto-updated.

Last update: 2024-09-24 05:13:35 UTC


README

安装

为需求包执行安装说明: https://github.com/kjdev/php-ext-jq

使用composer安装此包

composer require sobernt/jq-object

用法

用最少的参数初始化对象

$obj = new sobernt\JqObject\JqObject("{
    \"testkey\":\"testval\",
    \"testarray\":[
        \"testsimplearrayval1\",
        \"testsimplearrayval2\"
    ],
    \"testcompositearray\":[
        \"testcompositearrayval1\",
        {
             \"testcompositearray2key\": \"testcompositearray2value\"
        }
    ],
     \"testobject\":{
             \"testobjectkey\": \"testobjectval\",
             \"testobjectintkey\": \"1\"
    }
}");

完整的构造函数

__construct(string $json,bool $is_formatted=true,$depth=0,$max_depth=255)

$is_formated=false 设置为以字符串形式获取所有原始数据。将 $max_depth = 500 设置为重新配置对象最大递归级别 = 500

如果jq未安装,则抛出 InstallJqException

如果json无法解析,则抛出 JsonException

在类中发生所有其他服务错误\php警告时抛出 JQException

您可以用这个作为默认对象从json_encode,但使用此语法解析json的部分

$obj->testobject

此示例返回数组

$obj->testarray

此示例返回对象

$obj->testcompositearray[1]

如果 $is_formated=false,此示例返回字符串,否则返回 (int)1

$obj->testobject->testobjectintkey

如果调用对象未在json中找到,则抛出 InvalidArgumentException