Sign In Register

How can we help you today?

Start a new topic
Answered

GSData instead of JSON?

Hey, 


I made a new event with JSON as the type that I want to put in my Unity game.

When I go to fill in that json with a string that IS json, it says that it wants GSData instead of my expected JSON.



But it also won't let me fill in a GSData object (without converting my data to a dictionary first).

Is there a good way to go about this or is this a bug?


Thanks


Best Answer

Hi Travis


The JSON String will need to be parsed before you can send it with the API request.


You can use one of the API methods to do this:


GSRequestData parsedJson = new GSRequestData(json)


This object that then be used with the SDK.


Hope that helps


Gabriel


Answer

Hi Travis


The JSON String will need to be parsed before you can send it with the API request.


You can use one of the API methods to do this:


GSRequestData parsedJson = new GSRequestData(json)


This object that then be used with the SDK.


Hope that helps


Gabriel

Ah, awesome I hadn't had to use the JSON uploading yet so that will actually come in VERY handy for some of my upcoming stuff. Thanks a lot :)

K something is strange. When I try to do what Gabriel said above with 

var parsedJson = new GSRequestData(json);


with a completely valid JSON string, it doesn't insert anything into it. The GSData remains empty.

I can add it manually but then I have to also give it an extra name which I can't figure out how to not include it in my userData when I add the data to it. 


Second question is when I receive that data in my event, is there a way to tell if it has an array in it? I know it will but I can't seem to just add an element out of it for example. 

Were these last two questions ever answered? We'll be heading into this very shortly, and would be helpful.


Thanks

Jesse

Hi Travis


1 .To send JSON in a logEventRequest in unity you can use this code


To send JSON

GSRequestData jsonData = new GSRequestData ().AddNumber ("somekey", 1).AddString ("another", "data");




To send logeventRequest

LogEventRequest request = new LogEventRequest();

request.SetEventKey("YourEvent");

request.SetScriptData("jsonData", jsonData);

request.Send()

2. To check if your JSON contains an array you can use
Object.prototype.toString.call(json.element)=== '[object Array]'

Thanks
Katie

So just getting back to testing GSRequestData, 

Does this mean that I have to manually add each json field that I am wanting to send? I want to make sure that my inventory for players is synced and wouldn't be sending just one or two items but quite a lot. 

Is
var data = new GSRequestData(ValidJsonString);  broken? 


Cause I still have no way of just adding my valid JSON to the object it seems.

K, I didn't realize that I was using the Challenge version of the call I wanted :( 

Sooooo...yeah it works now <.< >.>

It think it should be SetEventAttribute instread of SetScriptData?

request.SetEventKey("YourEvent");

request.SetEventAttribute("jsonData", new GSRequestData(validJsonString));

request.Send()

 

Login to post a comment