序列化为 JSON 具有双重成员的对象时的堆栈溢出
Stack Overflow in serializing to JSON an Object with double members
尝试 运行 此代码使用 dartson 序列化 JSON 中的对象时,在成员中使用双精度值时会生成堆栈溢出异常。
我该如何解决这个问题?
import 'package:dartson/dartson.dart';
@MirrorsUsed(targets:const['example'], override:'*')
import 'dart:mirrors';
@Entity()
class GeoFence {
String label;
num latitude;
num longitude;
num radius;
}
main(List<String> args) {
var dson = new Dartson.JSON();
GeoFence object = new GeoFence()
..label = "test"
..latitude = 46.2
..longitude = 12
..radius = 10;
String jsonString = dson.encode(object);
print(jsonString);
}
这是一个已关闭的问题,但是 double 的序列化还没有生效GitHub issue
我尝试了您的示例,看起来 "num" 定义的属性中使用的双精度数存在问题。请尝试:
import 'package:dartson/dartson.dart';
@Entity()
class GeoFence {
String label;
double latitude;
double longitude;
double radius;
}
main(List<String> args) {
var dson = new Dartson.JSON();
GeoFence object = new GeoFence()
..label = "test"
..latitude = 46.2
..longitude = 12
..radius = 10;
String jsonString = dson.encode(object);
print(jsonString);
}
另请注意,使用 dartson 时不再需要 @MirrorUsed 注释。我会在 github 上更新问题并尽快查看。
尝试 运行 此代码使用 dartson 序列化 JSON 中的对象时,在成员中使用双精度值时会生成堆栈溢出异常。 我该如何解决这个问题?
import 'package:dartson/dartson.dart';
@MirrorsUsed(targets:const['example'], override:'*')
import 'dart:mirrors';
@Entity()
class GeoFence {
String label;
num latitude;
num longitude;
num radius;
}
main(List<String> args) {
var dson = new Dartson.JSON();
GeoFence object = new GeoFence()
..label = "test"
..latitude = 46.2
..longitude = 12
..radius = 10;
String jsonString = dson.encode(object);
print(jsonString);
}
这是一个已关闭的问题,但是 double 的序列化还没有生效GitHub issue
我尝试了您的示例,看起来 "num" 定义的属性中使用的双精度数存在问题。请尝试:
import 'package:dartson/dartson.dart';
@Entity()
class GeoFence {
String label;
double latitude;
double longitude;
double radius;
}
main(List<String> args) {
var dson = new Dartson.JSON();
GeoFence object = new GeoFence()
..label = "test"
..latitude = 46.2
..longitude = 12
..radius = 10;
String jsonString = dson.encode(object);
print(jsonString);
}
另请注意,使用 dartson 时不再需要 @MirrorUsed 注释。我会在 github 上更新问题并尽快查看。