2018 Nov 07 11:08 AM
So I am doing a get request to a webservice and getting from that a json.
The problem is that I am not able to convert it and I have tried three ways but all failed.
Try 1
I used the method cl_fdt_json=>json_to_data
call method cl_fdt_json=>json_to_data
exporting
iv_json = gv_response
changing
ca_data = gt_data_json.
And the table in output remains initial .
Try 2
data gr_json_deserializer type ref to cl_trex_json_deserializer
create object gr_json_deserializer.
call method gr_json_deserializer->deserialize
exporting
json = gv_response
importing
abap = gt_data_json.
Try 3
CALL TRANSFORMATION id
SOURCE XML gv_response
RESULT data = gt_data_json.
None of this is working .
Here is the json that has to be converted:
This is the structure I used to handle this.
types: begin of zstockblock,
qty_ordered type i,
sku type string,
end of zstockblock.
types: begin of z_stockblock_v,
entity_id type i,
items type zstockblock,
total_count type i,
end of z_stockblock_v.
data gt_data_json type table of z_stockblock_v
Don't look at the data type since I was going to change them if it was going to work
Can anyone help me ? I am stuck
So I am doing a get request to a webservice and getting from that a json.
The problem is that I am not able to convert it and I have tried three ways but all failed.
Try 1
I used the method cl_fdt_json=>json_to_data
call method cl_fdt_json=>json_to_data
exporting
iv_json = gv_response
changing
ca_data = gt_data_json.
And the table in output remains initial .
Try 2
data gr_json_deserializer type ref to cl_trex_json_deserializer
create object gr_json_deserializer.
call method gr_json_deserializer->deserialize
exporting
json = gv_response
importing
abap = gt_data_json.
Try 3
CALL TRANSFORMATION id
SOURCE XML gv_response
RESULT data = gt_data_json.
None of this is working .
Here is the json that has to be converted:
This is the structure I used to handle this.
types: begin of zstockblock,
qty_ordered type i,
sku type string,
end of zstockblock.
types: begin of z_stockblock_v,
entity_id type i,
items type zstockblock,
total_count type i,
end of z_stockblock_v.
data gt_data_json type table of z_stockblock_v
Don't look at the data type since I was going to change them if it was going to work
Can anyone help me ? I am stuck
2018 Nov 07 3:45 PM
Hi,
The CL_FDT_CLASS will work. There needs to be a little conversion before you pass values into the class.Check this link
https://answers.sap.com/questions/383255/how-to-convert-json-response-from-rest-api-to-abap.html
2018 Nov 08 7:59 AM
Which little conversion exactly? I can not see it in the URL
2018 Nov 08 7:18 PM
Hi Tomas,
Check this code segment..this works just fine for me.
TYPES : BEGIN OF str_json,
success(20),
msg(20),
matnr(20),
matkl(20),
END OF str_json.
DATA : response TYPE string VALUE '{"success":"false","msg":"Not valid","matnr":"1234","matkl":"123489"}',
lt_data_json TYPE str_json.
CALL METHOD cl_fdt_json=>json_to_data
EXPORTING
iv_json = response
CHANGING
ca_data = lt_data_json.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |