Sign In Register

How can we help you today?

Start a new topic
Answered

How to get array objects from Server?

Hi community, attempt i got this json


var ucdt = {ucdt : [{cn:'Joe', clv:[1, 3, 2, 1, 1, 2, 1, 3, 3]}, {cn:'Adam', clv:[1, 3, 2, 1, 1, 2, 1, 3, 3]}, 


        {cn:'Lim', clv:[1, 3, 2, 1, 1, 2, 1, 3, 3]}, {cn:'Def', clv:[1, 3, 2, 1, 1, 2, 1, 3, 3]}, {cn:'Bull', clv:[1, 3, 2, 1, 1, 2, 1, 3, 3]}]};


I'm done in sending to the client, but i dont know how to get this data? pls tell me


Best Answer

Hi Hu~u Ða?o,


This would depend how you're sending this data to the client, and which sdk you're using. For example, if you're sending it to the client using Spark.setScriptData("ucdt", ucdt);, and using our Unity SDK, you could retrieve it client side using:


var ucdt = response.ScriptData.GetGSDataList("ucdt"); //this will retrieve the array of objects

var el = ucdt[0]; //to get a specific element from your array

var cn = el.GetString("cn"); //to get the 'cn' from the array element

var clv = el.GetIntList("clv"); //to get the 'clv' array from the array element


Regards,

Vinnie


Answer

Hi Hu~u Ða?o,


This would depend how you're sending this data to the client, and which sdk you're using. For example, if you're sending it to the client using Spark.setScriptData("ucdt", ucdt);, and using our Unity SDK, you could retrieve it client side using:


var ucdt = response.ScriptData.GetGSDataList("ucdt"); //this will retrieve the array of objects

var el = ucdt[0]; //to get a specific element from your array

var cn = el.GetString("cn"); //to get the 'cn' from the array element

var clv = el.GetIntList("clv"); //to get the 'clv' array from the array element


Regards,

Vinnie

Thank for the support team,

In that case, your response is correct.

Now i have new issue

Attempt i got this Json:

{

  "b": [

    [

      "long nhan",

      "tay trong",

      "hanh hung",

      "cao tu",

      "tu tung"

    ]

  ]

}

How can i get that Array? When i used GetGSdataList("b")

But that Array count = 0

I dont know how to get list string or ... without key.

pls support me, thank you

let say i have json like this

array: [[array], [array]...], [[array], [array], [array]...]

How can i get my data?

Login to post a comment