GSON - Get JSON value from String

jan picture jan · Nov 22, 2013 · Viewed 82.8k times · Source

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?

Answer

Sanj picture Sanj · Nov 22, 2013
double result = jobj.get("test").getAsDouble();