嵌套列表 JSON 在 Oracle PLSQL Apex 中解析
Nested List JSON Parse in Oracle PLSQL Apex
--设置服务器输出;
DECLARE
p_json CLOB := '
{
"value": [
{
"id": "AAMkADFjOTE3MDZmLTY3YWMtNDA0ZS05OWNmLWNmM",
"ccRecipients": [
{
"emailAddress": {
"name": "Sudip Dutta",
"address": "duttasudip89@gmail.com"
}
},
{
"emailAddress": {
"name": "D Roy",
"address": "Droy@gmail.com"
}
}
]
}
]
}'
;
l_cc_email_address VARCHAR2(2000);
l_cc_email_addresses VARCHAR2(4000);
l_message_id VARCHAR2(4000);
BEGIN
apex_json.parse(p_json);
FOR cc_email_counter IN 1..apex_json.get_count(p_path => 'value.ccRecipients') LOOP
l_cc_email_address := NULL;
l_cc_email_address := apex_json.get_varchar2(p_path =>
'value[%d].ccRecipients[%d].emailAddress.address', p0 => cc_email_counter
);
dbms_output.put_line('New Iteration l_cc_email_addresses :- ' || l_cc_email_address);
END LOOP;
END;
我正在尝试解析以上 json 并希望在循环中打印“地址”标签值。不是不能做同样的事情。上面的代码我tried.Please help.
“值”是一个元素数组 [],里面只有一个元素 - 您需要在 apex_json.get_count
函数中选择第一个数组元素。
set serveroutput on size 999999
clear screen
DECLARE
l_json_text CLOB;
l_json_values apex_json.t_values;
BEGIN
l_json_text := '
{
"value": [
{
"id": "AAMkADFjOTE3MDZmLTY3YWMtNDA0ZS05OWNmLWNmM",
"ccRecipients": [
{
"emailAddress": {
"name": "Sudip Dutta",
"address": "duttasudip89@gmail.com"
}
},
{
"emailAddress": {
"name": "D Roy",
"address": "Droy@gmail.com"
}
}
]
}
]
}
';
apex_json.parse(
p_values => l_json_values,
p_source => l_json_text
);
FOR r IN 1 .. APEX_JSON.get_count(p_path => 'value[1].ccRecipients', p_values => l_json_values) LOOP
DBMS_OUTPUT.put_line('email address: '||apex_json.get_varchar2(p_path => 'value[1].ccRecipients[%d].emailAddress.address', p0 => r, p_values => l_json_values));
END LOOP;
END;
/
email address: duttasudip89@gmail.com
email address: Droy@gmail.com
--设置服务器输出;
DECLARE
p_json CLOB := '
{
"value": [
{
"id": "AAMkADFjOTE3MDZmLTY3YWMtNDA0ZS05OWNmLWNmM",
"ccRecipients": [
{
"emailAddress": {
"name": "Sudip Dutta",
"address": "duttasudip89@gmail.com"
}
},
{
"emailAddress": {
"name": "D Roy",
"address": "Droy@gmail.com"
}
}
]
}
]
}'
;
l_cc_email_address VARCHAR2(2000);
l_cc_email_addresses VARCHAR2(4000);
l_message_id VARCHAR2(4000);
BEGIN
apex_json.parse(p_json);
FOR cc_email_counter IN 1..apex_json.get_count(p_path => 'value.ccRecipients') LOOP
l_cc_email_address := NULL;
l_cc_email_address := apex_json.get_varchar2(p_path =>
'value[%d].ccRecipients[%d].emailAddress.address', p0 => cc_email_counter
);
dbms_output.put_line('New Iteration l_cc_email_addresses :- ' || l_cc_email_address);
END LOOP;
END;
我正在尝试解析以上 json 并希望在循环中打印“地址”标签值。不是不能做同样的事情。上面的代码我tried.Please help.
“值”是一个元素数组 [],里面只有一个元素 - 您需要在 apex_json.get_count
函数中选择第一个数组元素。
set serveroutput on size 999999
clear screen
DECLARE
l_json_text CLOB;
l_json_values apex_json.t_values;
BEGIN
l_json_text := '
{
"value": [
{
"id": "AAMkADFjOTE3MDZmLTY3YWMtNDA0ZS05OWNmLWNmM",
"ccRecipients": [
{
"emailAddress": {
"name": "Sudip Dutta",
"address": "duttasudip89@gmail.com"
}
},
{
"emailAddress": {
"name": "D Roy",
"address": "Droy@gmail.com"
}
}
]
}
]
}
';
apex_json.parse(
p_values => l_json_values,
p_source => l_json_text
);
FOR r IN 1 .. APEX_JSON.get_count(p_path => 'value[1].ccRecipients', p_values => l_json_values) LOOP
DBMS_OUTPUT.put_line('email address: '||apex_json.get_varchar2(p_path => 'value[1].ccRecipients[%d].emailAddress.address', p0 => r, p_values => l_json_values));
END LOOP;
END;
/
email address: duttasudip89@gmail.com
email address: Droy@gmail.com