JSON Utilities and SetArray

florian
2023-04-25
2024-05-11
  • florian - 2023-04-25

    Hi,
    I'm using JSON Utilities SL and have to write a struct like this:

    {
    "foo":"bar",
    "foobar":[
        {"Key1":"val1", "Key2":"val2"}
        ]
    }
    

    Up to "foobar" it's straight forward.
    Then I add SetArray(diIndex := 4, diParentIndex := 3);

    But when I want to add the next "Key1" with
    SetKey(wsKey := "Key1", diParentIndex := 4, diIndex := 5);
    I get an error "INVALID_KEY_PARENT".

    how can I set elements in the array?

     
  • i-campbell

    i-campbell - 2023-04-25

    That looks like an array of one object.
    maybe: SetArray();SetObject();SetKey();

     
  • florian - 2023-04-25

    Yes that was the solution.

    Thank you.

     
    • corriibme - 2024-05-11

      Hello @florian,
      Could you please help with how to set an array value? I've been trying to use the with the setKeyWithArray method which creates the key with an empty array value. But I have been unable to set items in this array?

      objindex:= fb_JBuilder.SetKeyWithArray("Key6", diParentIndex := diRootIndex);
      objindex2:= fb_JBuilder.SetValue(value:= iValue2, diParentIndex:= objindexx);
      

      //iValue: array[0..n] of int;

      Best regards

       

Log in to post a comment.