JSON Parse / Json Ayrıştırma : CL_CLB_PARSE_JSON

JSON ayrıştırma için bir alternatif

REPORT  ZMEHO_JSON2.



typesBEGIN OF ty_Structure_A ,
            DURUM type string,
            ID    type string,
            IL    type string,
            ILCE    type string,
      END OF ty_Structure_A.

typesBEGIN OF ty_Structure_B ,
            ACIKLAMA type string,
      END OF ty_Structure_B.

typesBEGIN OF  ty_DataSet ,
            Structure_A type ty_Structure_A,
            Structure_B type ty_Structure_B,

      END OF ty_DataSet.

typesBEGIN OF  ty_XML_out ,
            NewDataSet type ty_DataSet,
      END OF ty_XML_out.





datals_out_data type ty_XML_out.
datalv_response type string.
datalo_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.





Eğer Türkçe karakter problemi ile karşılaşırsanız
Servisten dönen veriyi XSTRING olarak alıp uygun code page ile stringe dönüştürün
      CL_BCS_CONVERT=>xstring_to_string(
          EXPORTING
            iv_xstr   = xresponse
            iv_cp     =  4110                " SAP character set identification
          RECEIVING
            rv_string = CHN_XML_RESPONSE
        ).