#Please share exactly how you call it

1 messages · Page 1 of 1 (latest)

marble harbor
#

An example

class RBS_CargoCb : RestCallback
{
    array <string> GetCargoFromJSON(string valueMain)
    {    

        SCR_JsonLoadContext reader();
        reader.LoadFromFile("$profile:/Relibus/cargo.json");
     
            ref CargoFromServer cargo = NewFromReader(reader, valueMain);
            PrintFormat("name: %1 container: %2",mc.CargoId, cargo.Container);
            return cargo.Container;
    } 
}

ref CargoFromServer NewFromReader(SCR_JsonLoadContext loadctx, string valueMain)
    {
            ref CargoFromServer cargo = new CargoFromServer();
            
            loadctx.ReadValue(valueMain, cargo );
            loadctx.ReadValue("CargoId", cargo.CargoId);
            loadctx.ReadValue("Container", cargo.Container);
        
        return cargo;
    }
class CargoFromServer
{
    string CargoId;
    array<string> Container;
}
#

in $profile:/Relibus/cargo.json
{"cargo1":{"CargoId":"cargo1","Container":["aaa", "sss"]},"cargo2":["aaa", "sss"]}

#
  "cargo1": {
    "CargoId": "cargo1",
    "Container": [
      "aaa",
      "sss"
    ]
  },
  "cargo2": [
    "aaa",
    "sss"
  ]
}
quick thorn
#

you are mixing upper and lower case

marble harbor
#

cargo2 is incorrect but Im trying to retrieve cargo1 anyway

quick thorn
#

write the json file from script once. Then you see how it should look like

marble harbor
#

i have

    {
         
     FileHandle cargoFile = FileIO.OpenFile("$profile:/Relibus/cargo.json", FileMode.WRITE);
            if(cargoFile)
        {
            cargoFile.Write(data);
            cargoFile.Close();
        } else{
            PrintFormat("failed to open and write %1", cargoFile);
        }
        ```
quick thorn
#

and remove theses

marble harbor
#

so it should be ok

#

oh

quick thorn
#

use that as making it a string in script first and then writing is vastly more expensive

marble harbor
#

Thanks! I will look closer. I thought the given datatype (array<string>) isn't supported in serialisation

quick thorn
#

they are, including map<string, string> etc

marble harbor
#

!

#

interesting!

marble harbor
#

it's super wierd. types like string, int are serialised well but with array<string> im keep getting storage is: 0x0000000000000000 {} meowsweatsmeowsweatsmeowsweatsmeowsweats

#

but now im reading not from the json file.

    array<string> GetFromJSON(string data) {
        SCR_JsonLoadContext reader();
        reader.ImportFromString(data);
        InventoryServerModel mc = NewFromReader(reader);
       return mc.Storage;
    }

it's from GET request

{"username":"","storage":["(6BCAA9E5BC957693)Prefabs/Characters/HeadGear/Hat_ZmijovkaCap_01/Hat_ZmijovkaCap_01_black.et","(50F8B1F928F93ABD)Prefabs/Characters/Uniforms/Shirt_Turtleneck_01/Shirt_Turtleneck_01_beige.et","(5A8C9A020BD7
ABA6)Prefabs/Characters/Uniforms/Pants_Trousers_01/Pants_Trousers_01_DarkGrey.et"]}```
marble harbor
#

it's working with string, int, float types. But there's no chance to get it working with array<string>

quick thorn
#

start simple to find out where your code fails. the load context supports it

quick thorn
#

Also fun fact while we are at it, serialize ResourceName directly, we have a nice internal handling for it so you get the readable paths in diag env but in production it will just the guids, saving on data size

tribal dagger
marble harbor
#
   ref array<string> GetFromJSON(string data) {
        SCR_JsonLoadContext reader();
        reader.ImportFromString(data);
        InventoryServerModel mc = NewFromReader(reader);
       return mc.Storage;
    }
class InventoryServerModel
{
        string Username;    
        ref a
rray<string> Storage;   
   

}


works!