04-18-2018 8:28 AM
Hello,
anybody please have sample code of how to deserialize JSON string with unknown structure via class /UI2/CL_JSON ? If I remember from reading wiki, it is the method which returns dynamically created data object...
Sadly the official WIKI page for this class is down: https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer
05-04-2018 4:01 PM
Hi Thomas,
/ui2/cl_json=>generate.
DATA: lv_json TYPE /ui2/cl_json=>json,
lr_data TYPE REF TO data.
FIELD-SYMBOLS: <data> TYPE data,
<struct> TYPE any,
<field> TYPE any.
lv_json = `{"name":"Key1","properties":{"field1":"Value1","field2":"Value2"}}`.
lr_data = /ui2/cl_json=>generate( json = lv_json ).
/ui2/cl_data_access=>create( ir_data = lr_data iv_component = `properties-field1`)->value( IMPORTING ev_data = lv_val ).
WRITE: lv_val.
Class /ui2/cl_data_access released with latest /ui2/cl_json correction note => 2526405
And yes, the wiki (actually the whole space) is deleted, by SDN, for some unknown reason. SDN colleges already 3rd week trying to restore it. And this is already the second time. But because now I am already experienced guy I have a copy of the page 😉
BR, Alexey.
05-04-2018 4:01 PM
Hi Thomas,
/ui2/cl_json=>generate.
DATA: lv_json TYPE /ui2/cl_json=>json,
lr_data TYPE REF TO data.
FIELD-SYMBOLS: <data> TYPE data,
<struct> TYPE any,
<field> TYPE any.
lv_json = `{"name":"Key1","properties":{"field1":"Value1","field2":"Value2"}}`.
lr_data = /ui2/cl_json=>generate( json = lv_json ).
/ui2/cl_data_access=>create( ir_data = lr_data iv_component = `properties-field1`)->value( IMPORTING ev_data = lv_val ).
WRITE: lv_val.
Class /ui2/cl_data_access released with latest /ui2/cl_json correction note => 2526405
And yes, the wiki (actually the whole space) is deleted, by SDN, for some unknown reason. SDN colleges already 3rd week trying to restore it. And this is already the second time. But because now I am already experienced guy I have a copy of the page 😉
BR, Alexey.
05-07-2018 7:49 AM
Hi Alexey, thank you very much! 🙂
Now I know why I couldnt find it in class. Our version of /ui2/cl_json does not have generate( ) method yet.
05-07-2018 9:47 AM
The GENERATE method was added with note 2429758. You can apply it on any backend from SAP_BASIS 700.
For best results, I would recommend adding and all subsequent notes: 2382783, 2368774, 2330592, 2300508, 2292558, 2526405.
06-01-2018 9:39 AM
Hi Alexey,
thanks a lot for providing a downport of /UI2/CL_JSON on One more ABAP to JSON Serializer and Deserializer
It was a great help on a 700 system (patch level SAPKB70031) and works as a charm!
Now I am working on a system with SAP_BASIS / SAP_UI 740. Unfortunately I cannot implement the latest note 2526405 to get the new class /UI2/CL_DATA_ACCESS, as note is assigned to SAPUI 750 only. Is this correct?
Best regards
Frank
06-04-2018 11:18 AM
Hi Frank,
SAP_UI 740 out of maintenance now and I, therefore, I can not create a correction for it. We do not have correction system for it, cannot apply/test the fix.
So, I am sorry, but I think you need to upgrade 😕
Another alternative, you can copy the code of /UI2/CL_DATA_ACCESS from here:
BR, Alexey.
06-07-2018 12:12 PM
Hi Alexey,
thank you for pointing that out, I wasn't aware of that. Ok, after the upgrade is before the upgrade...
BR, Frank
08-31-2018 10:27 AM
Hi Alexey,
I have tried out to implement the lastest note 2526405 but unfortunatly, i encounter very big issues...
I have one simple JSON with more than 200 fields but the result is totally messed up. Fields and values are shuffled, so they cannot be used.
I have found one bug in the case you have more than 2 fields starting with the same 30char, only is taken into account.
But i don't understand why the values are shuffled (even if I remove fields with identical first 30char)
Could you please tell me if another note can save me?
Kind Regards,
Guillaume
08-31-2018 3:23 PM
Hi Guillaume,
it is a known bug and it is fixed in note 2629179 . The 2526405 is not the latest one ;).
Please assist the central blog /UI2/CL_JSON , which is now once more alive, about latest updates.
Best regards,
Alexey.