Вам необходимо использовать библиотеку Джексона (jackson-databind
).
Код:
import java.io.IOException;
import java.util.Map;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Example {
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
String inputJson = "{ \n" +
" \"4562\": { \n" +
" \"a\": \"foo1\", \n" +
" \"b\": \"56\", \n" +
" \"c\": \"1342\" \n" +
" },\n" +
" \"4563\": { \n" +
" \"a\": \"foo2\", \n" +
" \"b\": \"57\", \n" +
" \"c\": \"1343\" \n" +
" }\n" +
"}";
Map<String, Map<String, String>> map = mapper.readValue(inputJson, Map.class);
System.out.println(map);
}
}
Вывод:
{4562={a=foo1, b=56, c=1342}, 4563={a=foo2, b=57, c=1343}}
Загрузите jar отсюда: https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.1/