Sign In Register

How can we help you today?

Start a new topic
Answered

What is the correct syntax for getting a list of ints from response.ScriptData within Unity?

Hey all!


I'm struggling to get the proper syntax when getting a simple list of ints from the cloud code I set up.


Cloud Code:


fdafdsf.png



Within unity, how do I go about converting the scriptdata to a list of ints? Or even an array of ints?


I tried doing something like 

List<int> list = response.ScriptData.GetIntList("unitData");

but it returns null.


Thanks for your time!


Best Answer

Hi Sean,


To parse a list of int, one way of going about it would be like so.


var myNums = JsonUtility.FromJson<Numbers>(response.ScriptData.JSON).myNumbers;


[Serializable]

private class Numbers

{

    public List<int> myNumbers;

}


Hope this helps,

 - Steve

1 Comment

Answer

Hi Sean,


To parse a list of int, one way of going about it would be like so.


var myNums = JsonUtility.FromJson<Numbers>(response.ScriptData.JSON).myNumbers;


[Serializable]

private class Numbers

{

    public List<int> myNumbers;

}


Hope this helps,

 - Steve

Login to post a comment