JSONNODE.get (String) Rückgabe von NULL [Duplicate]Java

Java-Forum
Anonymous
 JSONNODE.get (String) Rückgabe von NULL [Duplicate]

Post by Anonymous »

Ich versuche, ein Pojo aus einer JSON -Datei zu erstellen. Aber aus irgendeinem Grund node.get ("name"). AsText () gibt null . "com.fasterxml.jackson.databind.jsonnode.astext ()" Weil der Rückwert von "com.fasterxml.jackson.databind.jsonnode.get)" null. "AsText () to toString () Das Ergebnis war das gleiche.

Code: Select all

public static solution findSolution(String name){
File file = new File("/home/clementino/IdeaProjects/helloworldJava/problems.json");
ObjectMapper mapper = new ObjectMapper();
solution solution = new solution();
try {
JsonNode tree = mapper.readTree(file);
for(JsonNode node : tree){
if(node.get("name").asText().equalsIgnoreCase(name)){ //problema
solution = mapper.treeToValue(node, solution.class);
System.out.println(solution.getName());
}else{
System.out.println("problem doesnt exist");
}
}
}catch(Exception e){
System.out.println("error");
}
return solution;
}
< /code>
[b]problems.json:[/b]


{
"solution": [
{
"name":"twoSum",
"difficulty": "easy",
"status": "time exceeded",
"lastModified": "12-05-2025",
"testCase": false,
"source": "leetcode.com",
"language": "java"
},
{
"name": "Watermelon",
"difficulty": "easy",
"status": "working",
"lastModified": "05-02-2024",
"testCase": false,
"source": "codeforces.com",
"language": "C++"

}
]
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post