Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用GSON进行铸造_Java_Json_Casting_Gson - Fatal编程技术网

Java 如何使用GSON进行铸造

Java 如何使用GSON进行铸造,java,json,casting,gson,Java,Json,Casting,Gson,有没有办法使用GSON将json中的字符串值转换为int、long或double成员 我的意思是,我有一个json字符串,类似这样: {'timestamp':'1243274283728', 'distanse':'122.1'} 我想将这个json字符串映射到以下类的对象: public class TestClass { public long timestamp; public double distance; } 提前谢谢你这不管用吗 TestClass obj = n

有没有办法使用GSON将json中的字符串值转换为int、long或double成员

我的意思是,我有一个json字符串,类似这样:

{'timestamp':'1243274283728', 'distanse':'122.1'}
我想将这个json字符串映射到以下类的对象:

public class TestClass
{
   public long timestamp;
   public double distance;
}
提前谢谢你这不管用吗

TestClass obj = new Gson().fromJson(
   "{'timestamp':'1243274283728', 'distance':'122.1'}", 
   TestClass.class);

该死的。。。然后我在代码的其他地方遇到了另一个问题。非常感谢。