JSON Parse / Json Ayrıştırma : CL_CLB_PARSE_JSON
JSON ayrıştırma için bir alternatif
REPORT ZMEHO_JSON2.
types: BEGIN OF ty_Structure_A ,
DURUM type string,
ID type string,
IL type string,
ILCE type string,
END OF ty_Structure_A.
types: BEGIN OF ty_Structure_B ,
ACIKLAMA type string,
END OF ty_Structure_B.
types: BEGIN OF ty_DataSet ,
Structure_A type ty_Structure_A,
Structure_B type ty_Structure_B,
END OF ty_DataSet.
types: BEGIN OF ty_XML_out ,
NewDataSet type ty_DataSet,
END OF ty_XML_out.
data: ls_out_data type ty_XML_out.
data: lv_response type string.
data: lo_parser type REF TO CL_CLB_PARSE_JSON.
"{ "NewDataSet": { "Structure_A": { "DURUM": "0", "ID": "2744418", "IL": "İSTANBUL", "ILCE": "Gaziosmanpaşa" }, "Structure_B": { "ACIKLAMA": "vesaire vesaire" } } }
lv_response = `{ "NewDataSet": {`
&& `"Structure_A": { `
&& ` "DURUM": "0",`
&& `"ID": "2744418", `
&& `"IL": "İSTANBUL",`
&& `"ILCE": "Gaziosmanpaşa"`
&& `},`
&& `"Structure_B": {`
&& `"ACIKLAMA": "vesaire vesaire"`
&& `} } }`.
CREATE OBJECT lo_parser.
* try.
call method lo_parser->json_to_data
exporting
iv_json = lv_response
changing
c_data = ls_out_data
.
* catch cx_clb_technical .
* endtry.
BREAK-POINT.
EXPORTING
iv_xstr = xresponse
iv_cp = 4110 " SAP character set identification
RECEIVING
rv_string = CHN_XML_RESPONSE
).