Skip to Content

JSON encoding

Hello all

I need to send JSON data to a customer, for example :

[{"PERNR":"00000001","NACHN":"Smith","VORNA":"Jürgen"}]

This data will be sent and received via flat files, and also via OData in SEGW (SAP Gateway Builder). So I assume the name "Jürgen" for example would need to be encoded ..

Questions:

1) Do I need to encode this to UTF-8 ?

2) If so, how do I do this in ABAP ?

(If seen cl_abap_conv_out_ce=>create( encoding = '4110' ) - but this results in an XSTRING ? )

Thanks in advance !

Jan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 23, 2016 at 06:01 AM

    Of course it's XSTRING, how could it be stored another way? If you're in a Unicode system, characters in String or C are always stored in UTF-16, cannot be anything else (more exactly UCS-2).

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 23, 2016 at 06:00 AM

    see

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 23, 2016 at 06:10 AM

    cl_abap_conv_out_ce=>create( encoding = '4110' )


    A more convenient class is CL_ABAP_CODEPAGE, e.g.:


    DATA: str TYPE string,

    xstr TYPE xstring.

    xstr = cl_abap_codepage=>convert_to(

    source = str

    codepage = `UTF-8` ).

    You get a codepage representation of a character string in an xstring. Method convert_from does it vice versa.

    If you transform ABAP data with call transformation you can decide whether the result is a string or an xstring, where xstring is the recommended type.


    As Sandra said, ABAP characters are stored internally in UCS-2. But the standard transfer format for XML and JSON is UTF-8. Therfore, it makes sense to convert the internal ABAP representation into UTF-8 in an xstring.


    Horst

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.