Int value returned as Float in JSON response from API
A
Adam Walters
started a topic
almost 4 years ago
I have an event I am accessing from the HTTP API. In the cloud code for the event, I'm adding some additional data to a record from a collection before returning it:
Parsing JSON when the call is made from the Unity SDK seems to work fine. However, when I make the web request, the raw text JSON returned is converting 100 to 100.0. Here is a snippet of the JSON text: "rankInLeague":100.0
Other int values which are stored on the record in the collection return properly as an int w/o a decimal
This is causing problems as it thinks it should be converting a float. I was wondering what might be causing the API to convert this int to a float and append the decimal on the end and if there is anything I can do to resolve this.
3 people have this question
1 Comment
C
Colby Morgan
said
over 3 years ago
I am currently having the same issue. Any good way to force the API to not do this?
Adam Walters
I have an event I am accessing from the HTTP API. In the cloud code for the event, I'm adding some additional data to a record from a collection before returning it:
var cursor = queryResults.cursor();
while (cursor.hasNext()) {
var data = cursor.next().getData();
if (includeRank) {
data[this.rankInLeagueField] = getPlayerRankFromLeaderboard(data[this.playerIdField], getLBLeaderboardFromLeague(data[this.currentLeagueField]));
} else {
data[this.rankInLeagueField] = 100;
}
result.push(data);
}
Parsing JSON when the call is made from the Unity SDK seems to work fine. However, when I make the web request, the raw text JSON returned is converting 100 to 100.0. Here is a snippet of the JSON text: "rankInLeague":100.0
Other int values which are stored on the record in the collection return properly as an int w/o a decimal
This is causing problems as it thinks it should be converting a float. I was wondering what might be causing the API to convert this int to a float and append the decimal on the end and if there is anything I can do to resolve this.
3 people have this question