I ma using PLSQL. I have json. But when i parse the json, it retun empty. Here is the sample PLSQL code:
CREATE OR REPLACE PROCEDURE my_process
IS
myjson VARCHAR2 (32767):= '{"responseinfo":"<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>"}';
l_json_obj JSON_OBJECT_T;
requestinfo VARCHAR2 (32767);
BEGIN
BEGIN
l_json_obj := JSON_OBJECT_T.parse (myjson);
requestinfo := l_json_obj.get_string ('requestinfo');
END;
END;
When I want get requestinfo from json, it return empty. What is the wrong of my code.
>Solution :
Your JSON has the key responseinfo and you are trying to get the value for requestinfo; you are not going to get the value because the two are different.
If you want responseinfo (and not requestinfo) then:
CREATE OR REPLACE PROCEDURE my_process
IS
myjson VARCHAR2 (32767):= '{"responseinfo":"<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>"}';
l_json_obj JSON_OBJECT_T;
requestinfo VARCHAR2 (32767);
BEGIN
l_json_obj := JSON_OBJECT_T.parse (myjson);
requestinfo := l_json_obj.get_string ('responseinfo');
DBMS_OUTPUT.PUT_LINE(requestinfo);
END;
/
Outputs:
<TRANSACTION><RESPONSE_CODE>100</RESPONSE_CODE><RESPONSE_MSG>Duplicate Request Found.</RESPONSE_MSG></TRANSACTION>
If you do actually want requestinfo then that does not exist so a NULL response is valid.