neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 267 forks source link

Serialized Long type but reading as Double #214

Open Vedan opened 4 years ago

Vedan commented 4 years ago

Hello!

I am found than bug. Serialise long type for example (2610758670492575612) but after read has Double. Bug in read method. string s1 = @"[{""Pack_Num"": 30459,""ID"": 2610758670492575612,""Location"": ""clSpire#11635"",""Item"": ""clItem#23887""}]"; bb = Encoding.UTF8.GetBytes(s1); List<Dictionary<string, object>> d2 = JsonSerializer.Deserialize<List< Dictionary<string, object>>>(bb);

in d2[0]["ID"] - has Double but need long.

Regards, Paul

RamType0 commented 4 years ago

Q. Which is the type of 1?

  1. int
  2. uint
  3. long
  4. ulong
  5. byte
  6. sbyte
  7. short
  8. ushort
  9. float
  10. double
  11. decimal

Yeah,we cannot answer this question.

Vedan commented 4 years ago

Hi. You need parce by maximum. For Example: if from 0 to 255 - this is a Byte from 255 to 65535 this is a short and next. Float and double you can parce by decimal symbol for example 2.3 this is a float. This is will be a more correct and logically for better understand and coding. If you build this parcer in UTF8Json - this is will be a cool. Thank you. Paul

RamType0 commented 4 years ago

Hi.

You need parce by maximum. For Example: if from 0 to 255 - this is a Byte from 255 to 65535 this is a short and next.

I think that's really confusing. Maybe you are already confused. Why it is not a sbyte from 0 to 127?

Vedan commented 4 years ago

You can parce an SByte. I am not using this type and showed example with Byte. you can analise types: 1 byte in + and - Byte (SByte) 2 byte in + and - 4 byte + and - 8 byte + and - and float and double by decimal symbol

RamType0 commented 4 years ago

I have these issues about your proposal.

  1. Originally,the type of every number in JSON is number of JavaScript. number of JavaScript is a representation of double-precision floating point number. Representation of double-precision floating point number in .NET is System.Double,it is double in C#.

  2. Precision float.and decimal has different precision from double.

Vedan commented 4 years ago

I did not quite understand the question. (English is not my mother lang) You can determine the fractional data type by the separator character. If there is no separation sign, then this is an integer and that’s it. Next, you determine the dimension by the value of the number. Usually used only types of byte, short, int, long, float, double. From string convert you can use 1) if has symbols "." or"," - than is fractional and than float.TryParce() and if return false than double.TryParce(). 2) else if has only digits from 0 to 9 - this is a byte.TryParce() is return false short.TryParce() is return false int.TryParce() is return false long.TryParce()

RamType0 commented 4 years ago

I didn't mean precision of type-expection. I said about difference of precision between floating point number types. Number in JSON should have precision of double-precision floating point number.