I'm trying to get translation from web dictionary. Here is a piece of Json which I want to parse using JsonNode.
{
"result" : "ok",
"tuc" : [ {
"phrase" : {
"text" : "powitanie",
"language" : "pl"
}
and java code:
try {
JsonNode node = translationMapper.readTree(jsonContent);
String result = node.get("result").asText();
System.out.println("result: " + result);
JsonNode tuc = node.get("tuc").get(0);
JsonNode phrase = tuc.get("phrase").get(0);
String textPhrase = phrase.get("text").asText();
System.out.println("translation: " + textPhrase);
}
catch (IOException e) {
e.printStackTrace();
}
output:
result: ok
Exception in thread "main" java.lang.NullPointerException at Requests.main(Requests.java:63)
line 63 is:
String textPhrase = phrase.get("text").asText();