PL SQL Apex_JSON - 解析元素名称

PL SQL Apex_JSON - Parse element name

我正在尝试从以下数组中获取值 -

{
   "list:" [
     {
       "User.name":"AAA"
     },
     {
       "User.Name":"BBB"
     }
  ]  
}

我试图获取名称值,但我得到的是空值 -

for i in 1..Apex_Json.get_count('list') loop
     l_name := Apex_Json.Get_varchar2('list[%d].User.Name', i);
end loop;

如何获取名称值?

“列表”是 json 元素数组。据我所知,您不能直接访问元素,但可以遍历数组以检查是否存在具有特定名称的元素。这是一个例子:

DECLARE
  l_json_text VARCHAR2(4000);
  l_json_values    apex_json.t_values;
  l_name      VARCHAR2(4000);
BEGIN
l_json_text := q'!
{
   "list": [
     {
       "User.name":"AAA"
     },
     {
       "User.Name":"BBB"
     }
  ]  
}
!';

  apex_json.parse(
    p_values => l_json_values,
    p_source => l_json_text
  );
  
  -- get nr of elements in the array and loop through it.    
  FOR r IN 1 .. APEX_JSON.get_count(p_path => 'list', p_values => l_json_values) LOOP
    -- get the value for User.Name for this array index. 
    -- If it is doesn't exist it will be NULL
    l_name := apex_json.get_varchar2(p_path => 'list[%d]."User.name"', p0 => r, p_values => l_json_values);
    IF l_name IS NOT NULL THEN
      DBMS_OUTPUT.put_line('"User.name":'||l_name);
    END IF;
  END LOOP;
END;
/

请注意,您的问题 json 有错别字:"list:" [ 应该是 "list": [