| |
|
»
»
|
|
| |
Re: How to avoid JSONEncode messing with numbers?
|
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:15 PM |
t = {1.925} print(game:GetService("HttpService"):JSONEncode(t)) --> [1.92500000000000004440892098501]
I get that this is from rounding to the nearest power of 2, but I want my numbers to cut off after 3 decimal places so it takes up less space saving. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Apr 2015 07:16 PM |
It's actually not JSON's fault, as you said. Store it as a string :) |
|
|
| Report Abuse |
|
|
robotmega
|
  |
| Joined: 16 May 2009 |
| Total Posts: 14084 |
|
|
| 28 Apr 2015 07:17 PM |
works for me
> t = {1.925} print(game:GetService("HttpService"):JSONEncode(t))
-->[1.925] |
|
|
| Report Abuse |
|
|
Abstains
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 6222 |
|
|
| 28 Apr 2015 07:18 PM |
@Robotmega
u should give me robotmega on gametest1 >:)
or sell me et
-iSoulZy/InsanelyCold, LMaD'ing since 2012. Add 21k posts to my post count. R$110,390 Tx461 RAP: 37,120 |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Abstains
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 6222 |
|
|
| 28 Apr 2015 07:20 PM |
yeah ik sorry
-iSoulZy/InsanelyCold, LMaD'ing since 2012. Add 21k posts to my post count. R$110,390 Tx461 RAP: 37,120 |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:20 PM |
w/e it's from storing the number in data
Do I really have to store it as a string? That adds 2 quotation characters per number. Is there a way to have it encode just the quantity? |
|
|
| Report Abuse |
|
|
Abstains
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 6222 |
|
|
| 28 Apr 2015 07:21 PM |
works for me btw
-iSoulZy/InsanelyCold, LMaD'ing since 2012. Add 21k posts to my post count. R$110,390 Tx461 RAP: 37,120 |
|
|
| Report Abuse |
|
|
robotmega
|
  |
| Joined: 16 May 2009 |
| Total Posts: 14084 |
|
|
| 28 Apr 2015 07:21 PM |
do u think im stupid rip 110,390 robux |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Apr 2015 07:22 PM |
| Well you can always just store '1925' and divide it (or just scale everything by 1000) |
|
|
| Report Abuse |
|
|
Abstains
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 6222 |
|
|
| 28 Apr 2015 07:22 PM |
y so serious? xd
-iSoulZy/InsanelyCold, LMaD'ing since 2012. Add 21k posts to my post count. R$110,390 Tx461 RAP: 37,120 |
|
|
| Report Abuse |
|
|
Abstains
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 6222 |
|
|
| 28 Apr 2015 07:23 PM |
i dont do offsite deals
tho ppl been pm'ing me about it
almost even got kl'ed
time 2 go back 2 lmad
-iSoulZy/InsanelyCold, LMaD'ing since 2012. Add 21k posts to my post count. R$110,390 Tx461 RAP: 37,120 |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:24 PM |
I'd like to just be able to do:
CFrame.new(unpack(t))
when I decode it... |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2015 07:25 PM |
| This worked fine for me was well, and I tested it on a Roblox game server and it worked fine there, too. Is this problem only occurring in Roblox Studio? |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:26 PM |
CFrame.new(unpack(t)) actually works with a full table of strings...
but I'm still bothered by all the unwanted quotations
{"Structure":{"Left Arm":[],"Right Arm":[],"Handle":{"_MagUnion":[],"MagUnion":[]}},"KeyFrames":[{"_MagUnion":["0","-1.581","-0.854","0","0","1","0","1","0","-1","0","0"],"Handle":["0.8","1.35","-1","0.998","0","0.07","0","1","0","-0.07","0","0.998"],"Left Arm":["-0.147","0.323","-1.291","0.69","-0.72","-0.068","0","0.094","-0.996","0.723","0.687","0.065"],"Right Arm":["1.379","0.397","-0.144","0.765","0.566","0.308","0","0.478","-0.878","-0.644","0.672","0.366"],"timeIndex":1,"MagUnion":["0","-1.581","-0.854","0","0","1","0","1","0","-1","0","0"]}],"Sequence":["TransitionKeyFrame(1)"]} |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:27 PM |
| I have no clue how it works for all of you and not me. I'm testing it in studio and Play Solo and it gets expanded like this. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:31 PM |
Well it's prettier than:
[{"_MagUnion":[0,-1.58099999999999996092014953319,-0.853999999999999981348253186297,0,0,1,0,1,0,-1,0,0],"Handle":[0.800000000000000044408920985006,1.35000000000000008881784197001,-1,0.9979999999999999982236431606,0,0.0700000000000000066613381477509,0,1,0,-0.0700000000000000066613381477509,0,0.9979999999999999982236431606],"Left Arm":[-0.146999999999999991784349617774,0.323000000000000009325873406851,-1.29099999999999992539301274519,0.689999999999999946709294817992,-0.719999999999999973354647408996,-0.0680000000000000048849813083507,0,0.094000000000000000222044604925,-0.995999999999999996447286321199,0.722999999999999976019182668097,0.687000000000000055067062021408,0.0650000000000000022204460492503],"Right Arm":[1.3790000000000000035527136788,0.397000000000000019539925233403,-0.143999999999999989119814358673,0.765000000000000013322676295502,0.565999999999999947597473237693,0.307999999999999996003197111349,0,0.477999999999999980460074766597,-0.8780000000000000026645352591,-0.644000000000000016875389974302,0.672000000000000041744385725906,0.365999999999999992006394222699],"timeIndex":1,"MagUnion":[0,-1.58099999999999996092014953319,-0.853999999999999981348253186297,0,0,1,0,1,0,-1,0,0]}] {"Structure":{"Left Arm":[],"Right Arm":[],"Handle":{"_MagUnion":[],"MagUnion":[]}},"KeyFrames":[{"_MagUnion":[0,-1.58099999999999996092014953319,-0.853999999999999981348253186297,0,0,1,0,1,0,-1,0,0],"Handle":[0.800000000000000044408920985006,1.35000000000000008881784197001,-1,0.9979999999999999982236431606,0,0.0700000000000000066613381477509,0,1,0,-0.0700000000000000066613381477509,0,0.9979999999999999982236431606],"Left Arm":[-0.146999999999999991784349617774,0.323000000000000009325873406851,-1.29099999999999992539301274519,0.689999999999999946709294817992,-0.719999999999999973354647408996,-0.0680000000000000048849813083507,0,0.094000000000000000222044604925,-0.995999999999999996447286321199,0.722999999999999976019182668097,0.687000000000000055067062021408,0.0650000000000000022204460492503],"Right Arm":[1.3790000000000000035527136788,0.397000000000000019539925233403,-0.143999999999999989119814358673,0.765000000000000013322676295502,0.565999999999999947597473237693,0.307999999999999996003197111349,0,0.477999999999999980460074766597,-0.8780000000000000026645352591,-0.644000000000000016875389974302,0.672000000000000041744385725906,0.365999999999999992006394222699],"timeIndex":1,"MagUnion":[0,-1.58099999999999996092014953319,-0.853999999999999981348253186297,0,0,1,0,1,0,-1,0,0]}],"Sequence":["TransitionKeyFrame(1)"]}
but I feel like there should be a way to keep it as a number and have it correctly stop at 3 decimals. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Apr 2015 07:33 PM |
Well you can always use gsub and "clean" the JSON table. Something like
%d+%.(%d+), function(lala) return tonumber(tostring(lala:sub(1, 3))); end |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 28 Apr 2015 07:35 PM |
| You could also make your own JSON encoder. It shouldn't be that hard or long if your just doing numbers. |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 28 Apr 2015 07:36 PM |
But then you can't distinguish between a true string "1" and what should be the number 1.
Like if one of the parts I was animating was named "1", that would break it. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Apr 2015 08:23 PM |
Actually it wouldn't break it, it would ignore that.
Anyways you can make sure there is no leading quotes. |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|