I would like to parse data from JSON which is of type String
.
I am using Google Gson.
I have:
jsonLine = \"
{
\"data\": {
\"translati
Simplest thing usually is to create matching Object hierarchy, like so:
public class Wrapper {
public Data data;
}
static class Data {
public Translation[] translations;
}
static class Translation {
public String translatedText;
}
and then bind using GSON, traverse object hierarchy via fields. Adding getters and setters is pointless for basic data containers.
So something like:
Wrapper value = GSON.fromJSON(jsonString, Wrapper.class);
String text = value.data.translations[0].translatedText;