ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Yajl_addChar and UTF-8 variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Yajl_addChar and UTF-8 variable

    Hi all,

    I'm coding an application, using Scott Klement's YAJL, and I need to use different languages (with different codings, like russian, greek, and so on).

    I have read a lot over this, but I don't have it clear...

    I have a file, with a field defined like this:

    // ....
    D FIELD S 100A CCSID(1208) // This is an UTF8 field, so I can store there words in russian, greek, spanish, ....
    // ....


    When I'm trying to generate a JSON, with YAJL library, I need to use YAJL_AddChar( xxxx ); with an *UTF8 field, but I can't...

    Maybe Im not doing it well, but I will appreciate some help :-)


    Thanks,

  • #2
    The parameters on yajl_addChar() are defined as EBCDIC strings. When you call YAJL_addChar(), RPG should automatically translate your UTF-8 field to EBCDIC, pass it to yajl_addChar, which will convert it bsck to UTF-8 before adding it to the document.

    Since it will be temporarily converted to EBCDIC, you will lose any values that are not valid in your job's EBCDIC.

    Is that what you're trying to do?

    You could also consider using yajl_gen_string() which expects input in UTF-8. Or, better yet, simply use the DATA-GEN opcode.

    Comment


    • #3
      I cannot use data-gen by the moment, so I will try with YAJL_gen_string. But I am not sure how to use it....


      May I have something like this ?


      d @pdata200 s *
      d @data200 s 200a based(@pdata200)
      d @test s 200a

      // ....


      read rfile;

      // ...

      @test = 'Test';
      yajl_addchar('test':@test);

      @data200 = field; // file is utf8 coded.
      @status = yajl_gen_string(@generator:@pdata200:%len(%str(@pd ata200)));

      // ...


      How is @data200 added to the JSON structure ?

      Comment


      • #4
        Its not clear how your example is meant to work? Typically, yajl_gen_string() would be used when calling the C API instead of the RPG routines like yajl_addChar. The RPG routines use a generator that's stored within the YAJLR4 service program that it does not expose to your RPG program.

        Perhaps it'd be easier to call yajl_addUtf16() instead?

        Otherwise, I could add a routine meant to add a UTF-8 string.

        Comment


        • #5
          With YAJL_addUTF16 is working fine for me, thanks.

          I didn't know that there were this procedure... :-)


          Thanks, Scott.

          Comment

          Working...
          X