GSON - 从String中获取JSON值 [英] GSON - Get JSON value from String
本文介绍了GSON - 从String中获取JSON值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析JSON字符串{'test':'100.00'},并使用GSON库获取值:100.00。我的代码如下所示:
String myJSONString ={'test':'100.00'};
JsonObject jobj = new Gson()。fromJson(myJSONString,JsonObject.class);
字符串结果= jobj.get(test)。toString();
System.out.println(result);
我的结果如下所示:100.00,但我不需要引号就只需要100.00。这怎么可以实现?
解决方案
double result = jobj.get(test)。getAsDouble();
I trying to parse the JSON String "{'test': '100.00'}" and to get the value: 100.00 with the GSON library. My code looks like this:
String myJSONString = "{'test': '100.00'}";
JsonObject jobj = new Gson().fromJson(myJSONString, JsonObject.class);
String result = jobj.get("test").toString();
System.out.println(result);
My result looks like this: "100.00", but I would need just 100.00 without the quotes. How can this be archieved?
解决方案
double result = jobj.get("test").getAsDouble();
这篇关于GSON - 从String中获取JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文