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.
T
Travis Evashkevich
said
about 7 years ago
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.
J
Jesse Comb
said
about 7 years ago
Were these last two questions ever answered? We'll be heading into this very shortly, and would be helpful.
Thanks
Jesse
Customer Support
said
about 7 years ago
Hi Travis
1 .To send JSON in a logEventRequest in unity you can use this code
Travis Evashkevich
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
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
- Oldest First
- Popular
- Newest First
Sorted by PopularTravis Evashkevich
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.
Travis Evashkevich
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.
Jesse Comb
Were these last two questions ever answered? We'll be heading into this very shortly, and would be helpful.
Thanks
Jesse
Customer Support
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
Richard Fu
request.SetEventKey("YourEvent");
request.SetEventAttribute("jsonData", new GSRequestData(validJsonString));
request.Send()Travis Evashkevich
K, I didn't realize that I was using the Challenge version of the call I wanted :(
Sooooo...yeah it works now <.< >.>
Travis Evashkevich
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 :)
Tech Support
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
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics