on 2019 Aug 01 2:51 PM
I'm using the following ABAP function to populate an existing ABAP table from json.
The JSON is correct, and the Table contains corresponding tables within tables.
<code>/ui2/cl_json=>deserialize( EXPORTING json = lv_json
CHANGING data = lt_abap ).
Running this returns a blank lt_abap table.
When changing the output to be a structure this works fine. But the problem is a need a TABLE, rather than a STRUCTURE for subsequent calls
<code>/ui2/cl_json=>deserialize( EXPORTING json = lv_json
CHANGING data = ls_abap
Can anyone suggest a solution o get he JSON into my TABLE?
Request clarification before answering.
Hello Adam,
The JSON string will only be deserialized to a table if you provide an array as input, not a JSON object as you did.
What about simply appending the results to a table?
/ui2/cl_json=>deserialize( EXPORTING json = lv_json
CHANGING data = ls_abap ).
INSERT ls_abap INTO TABLE lt_abap.
BR,
Gábor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Adam,
May be construct a deep structure and embed a table inside them. Also below method provides exception handling.
Regards
Prabha
data: lr_json type ref to /ui2/cl_json.
IF lv_json_data IS NOT INITIAL.
CREATE OBJECT lr_json.
TRY .
lr_json->deserialize_int( EXPORTING json = lv_json_data CHANGING data = ls_slack_data ).
ENDIF.
CATCH cx_sy_move_cast_error INTO DATA(lo_move_cast_error) .
DATA(lv_msg_desrl_err) = `HTTP GET failed: ` && lo_move_cast_error->get_longtext( ).
FREE:l_wa_reason,lo_move_cast_error.
ENDTRY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Couldn't have been simpler...
/ui2/cl_json=>deserialize( EXPORTING json = lv_json
CHANGING data = lS_abap ).
APPEND LS_abap TO lt_abap.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do we convert a boolean & null value to json from abap and viceversa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
{
"Id": "1369130",
"Venueid": "0005",
"Userid": "1320625",
"Menuid": "null",
"Created": "2019-07-29T08:18:35.000+0000",
"items": [
{
"Id": "4255354",
"Total": "3.10",
"Price": "2.80",
"Qty": "1",
"Orderid": "1369130",
"Menuitemid": "1447268",
"Externalid": "",
"Name": "Breakfast Roll Deal",
"modifiers": [
{
"Price": "0.00",
"Qty": "1",
"Id": "0000001",
"Orderitemid": "4255354",
"Externalid": "1000716",
"Name": "Bacon and Sausage Corn Topped Roll"
},
{
"Price": "0.30",
"Qty": "1",
"Id": "00000002",
"Orderitemid": "4255354",
"Externalid": "E1001587",
"Name": "Extra Sausage"
},
{
"Price": "0.00",
"Qty": "1",
"Id": "00000003",
"Orderitemid": "4255354",
"Externalid": "1000774",
"Name": "Latte"
},
{
"Price": "0.00",
"Qty": "1",
"Id": "00000004",
"Orderitemid": "4255354",
"Externalid": "E",
"Name": "Spread"
}
]
}
]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
60 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.