首页 > 解决方案 > 更改使用 APEX_JSON 解析的 JSON 对象

问题描述

我希望能够更改使用 APEX_JSON.parse()函数解析的 JSON 对象,但我在官方文档中一无所获,也没有关于此的提示或示例。

在下面的代码中,我在特定点中添加了注释,以便清楚地了解我的需求。

SET SERVEROUTPUT ON 

DECLARE
    j apex_json.t_values;
    l_paths apex_t_varchar2;    
    writers clob;
    json_object_result clob;
BEGIN

    writers := '[
        {
            "id": null,
            "hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f",
            "description": "Machado de Assis",
            "base64Img": "8eNZ28Dh5rZQIPhNEfwqoo1LCVx..."
        },
        {
            "id": 151,
            "hashCode": "a8f15eda80c50adb0e71943adc8015cf",
            "description": "José Alencar",
            "base64Img": "/XIQIHCol8eNZ28Dh5rZQIPhNEfwqoo1LCVx/9k=..."
        }
    ]';

    apex_json.parse(j, writers);

    l_paths := apex_json.find_paths_like (
        p_values         => j,
        p_return_path => '[%]',
        p_subpath       => '.hashCode',
        p_value    => '7ef605fc8dba5425d6965fbd4c8fbe1f'
    );

    dbms_output.put_line('Itens found: ' || l_paths.count);

    if (l_paths.count = 1) then 
        dbms_output.put_line('id: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.id'));
        dbms_output.put_line('hashCode: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.hashCode'));
        dbms_output.put_line('description: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.description'));
        dbms_output.put_line('base64Img: ' || apex_json.get_varchar2(p_values => j, p_path => l_paths(1) || '.base64Img'));
--      Here I would like to nullify base64Img attribute value
        json_object_result := 'here goes the object matched in the search with the base64Img attribute value null';
    end if;

END;

在我的json_object_result变量中,我想保存apex_json.find_paths_like()与它的base64Img属性 null 匹配的 JSON 对象。在我的示例中,结果将是

{ "id": null, "hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f", "description": "Machado de Assis", "base64Img": "" }

或者

{ "id": null, "hashCode": "7ef605fc8dba5425d6965fbd4c8fbe1f", "description": "Machado de Assis" }

有可能用 做类似的东西APEX_JSON吗?

标签: plsqloracle11goracle-apexoracle-apex-5oracle-apex-5.1

解决方案


推荐阅读