问题
I am trying to parse a JSON object into an APEX select list. There are ways to parse a JSON object, but I have not yet come across or figured a way to parse a JSON object and use it as a select list in the Apex application. Most questions have been around generating JSON from the Apex data. Any help would be appreciated. Thanks!
The data I want to parse (simpler example) is as below:
{
"verumModelObjectName": "Address",
"verumObjectList": [
{
"locationID": "20005",
"country": "ARE"
},
{
"locationID": "31083",
"country": "ARE"
},
{
"locationID": "31118",
"country": "ARE"
},
{
"locationID": "32185",
"country": "ARE"
},
{
"locationID": "32138",
"country": "ARE"
},
{
"locationID": "32070",
"country": "ARE"
},
{
"locationID": "32094",
"country": "ARE"
},
{
"locationID": "20006",
"country": "ARG"
},
{
"locationID": "32196",
"country": "ARG"
},
{
"locationID": "41057",
"country": "ARG"
},
{
"locationID": "31032",
"country": "ARG"
},
{
"locationID": "33212",
"country": "ARG"
},
{
"locationID": "3558",
"country": "ARG"
},
{
"locationID": "33126",
"country": "ARG"
},
{
"locationID": "31007",
"country": "ARG"
},
{
"locationID": "33127",
"country": "ARG"
},
{
"locationID": "31100",
"country": "ASM"
},
{
"locationID": "20008",
"country": "AUS"
},
{
"locationID": "20591",
"country": "AUS"
},
{
"locationID": "31125",
"country": "AUS"
}]
"statusCode": 200
}
回答1:
did you check apex_json package in 5.0 https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_json.htm#AEAPI29640
you can parse your data by using this package and then for select list you should create a dynamic select list with d display and r return values as below. it should work
select col1 d, col2 r
from xmltable (
'/json/verumObjectList/row'
passing apex_json.to_xmltype('
{
"verumModelObjectName": "Address",
"verumObjectList": [
{
"locationID": "20005",
"country": "ARE"
},
{
"locationID": "31083",
"country": "ARE"
},
{
"locationID": "31118",
"country": "ARE"
},
{
"locationID": "32185",
"country": "ARE"
},
{
"locationID": "32138",
"country": "ARE"
},
{
"locationID": "32070",
"country": "ARE"
},
{
"locationID": "32094",
"country": "ARE"
},
{
"locationID": "20006",
"country": "ARG"
},
{
"locationID": "32196",
"country": "ARG"
},
{
"locationID": "41057",
"country": "ARG"
},
{
"locationID": "31032",
"country": "ARG"
},
{
"locationID": "33212",
"country": "ARG"
},
{
"locationID": "3558",
"country": "ARG"
},
{
"locationID": "33126",
"country": "ARG"
},
{
"locationID": "31007",
"country": "ARG"
},
{
"locationID": "33127",
"country": "ARG"
},
{
"locationID": "31100",
"country": "ASM"
},
{
"locationID": "20008",
"country": "AUS"
},
{
"locationID": "20591",
"country": "AUS"
},
{
"locationID": "31125",
"country": "AUS"
}],
"statusCode": 200
}
')
columns
col1 number path '/row/locationID',
col2 varchar2(5) path '/row/country' );
来源:https://stackoverflow.com/questions/32603894/parse-json-object-to-use-in-apex-item-select-list