Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support double data without "d" suffix #3

Closed
ismlsmile opened this issue Feb 11, 2020 · 2 comments
Closed

support double data without "d" suffix #3

ismlsmile opened this issue Feb 11, 2020 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ismlsmile
Copy link

example:

import 'package:gson/gson.dart';

main()
{
var a = gson.decode('{aa:1.1}');
print(a);
}

error:
Unhandled exception:
type 'double' is not a subtype of type 'int'
#0 GsonDecoder.decodeNumber (package:gson/decoder.dart:230:31)
#1 GsonDecoder.decode (package:gson/decoder.dart:40:14)
#2 GsonDecoder.decodeMap (package:gson/decoder.dart:125:20)
#3 GsonDecoder.decode (package:gson/decoder.dart:25:14)
#4 Gson.decode (package:gson/gson.dart:80:20)
#5 main (file:///D:/Code/TestDart/bin/main.dart:5:16)
#6 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

@ismlsmile
Copy link
Author

in decoder.dart, modify like this, it it ok?

  case "d":
    ret = new Double(num.parse(number));
    if (!p.ended) {
      p.skip();
    }
    break;
  default:
    if(number.indexOf(".") != -1)
    {
      ret = new Double(double.parse(number));
    }
    else
    {
      ret = new Integer(num.parse(number));
    }

    break;

@MinimineLP MinimineLP added bug Something isn't working good first issue Good for newcomers labels Feb 11, 2020
@MinimineLP
Copy link
Owner

Yes, thank you, I was able to recreate the exception and your solution also fixes it, thank you very much, I will commit the solution.

Minimine

MinimineLP added a commit that referenced this issue Feb 11, 2020
Fixed issue #3 (support double data without "d" suffix #3)

Doubles that are not suffixed with "d" will not generate exceptions anymore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants