ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Rpg pointers

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

  • Rpg pointers

    I am using a webservice via an api call and YAJL. I am using :
    yajl_buf_load_tree((%ADDR(rspn)
    : %len(%trim(rspn))
    : json_msg)

    This returns an object with a few parameters, including an array called logs, I am fetching it with yajl.:
    loglist = yajl_object_find(json_data: 'log');
    The loglist is says it's type is a pointer(16);

    My issue is that after looping through the array, eventually I lose connection to the api and I am no longer able to reestablish a connection after 160 + iterations. I figured the best way to avoid this
    would be to save the results from the loglist and place it into an array. But I am not really sure how to do this.

    1. What kind of array do I need to store this data ?
    2. Do I have to use pointers ?
    3. What's the best approach

    Thank you for any help that I receive.

  • #2
    The node entries in YAJL are just pointers, so if you want to store them in an array you just need to define an array of pointers. Better yet - use the method that Scott designed into the package and define the array entries as being Like(yajl_val) - that way you won't confuse those who come after you.

    You don't say what error you are seeing when you say "eventually I lose connection" - there is no "connection" so what tells you have lost anything? If there is an underlying problem, there is no guarantee that retaining the pointer will help anyway.

    Have you got something like this in your code? If so, why not process each 'log' as you encounter it - why try to save them for later?

    Code:
           Dow YAJL_ARRAY_LOOP( loglist: c: logItemNode );

    Comment


    • #3
      P.S. A sample of the JSON and a bit more info on what you are doing with the content would be helpful in suggesting an approach.

      And if by "lose connection" you meant that it returned an invalid pointer that could just mean you have processed all of the log entries.

      Comment


      • #4
        Thank you for your reply, actually that is what I am doing, sorry I should have explained a bit more,, so I am looping through the array, but as soon as c increments and gets too around 58. It says error : connection has been lost, which disallows me wrong writing into the tb I am trying to write in. Essentially, what I wanted to do is find a way to grab the full array and place it inside of another array, rather than relying on being connected to extract the array before even doing this loop. I could possibly extract it from the response string, but I wanted to avoid that.
        Dow YAJL_ARRAY_LOOP( loglist: c: logItemNode );

        Code:
        Json example {
        logs = [
        {"notificationUri": "sample string", "allowMarkup": "sample string", "createdDateTime": "sample string", "lastModifiedDateTime": "sample string", "deliveredDateTime": "sample string", },
        {"notificationUri": "sample string", "allowMarkup": "sample string", "createdDateTime": "sample string", "lastModifiedDateTime": "sample string", "deliveredDateTime": "sample string", },
        {"notificationUri": "sample string", "allowMarkup": "sample string", "createdDateTime": "sample string", "lastModifiedDateTime": "sample string", "deliveredDateTime": "sample string", }, ] }

        Comment


        • #5
          What happens if you ask it for the element count with YAJL_ARRAY_SIZE ? Is it able to give an accurate count? If so then try starting at a higher number with YAJL_ARRAY_LOOP. For example if the count comes back as 100 - try setting your counter to (say) say 90 rather than zero to begin the process. If that works you may be able to process it in chunks.

          Also when you say "It says error : connection has been lost" what is "It" - where are you getting the error message from? What's the message Id (if it has one) - which program is issuing it etc.

          Comment

          Working...
          X