<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>ion</artifactId> <version>2.10.1</version> </dependency> import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.ion.IonObjectMapper; public class IonExample { public static void main(String[] args) { IonSystem ionSystem = IonSystemBuilder.standard().build(); String json = "{\"name\": \"Alice\", \"age\": 25}"; try { IonReader reader = ionSystem.newReader(json); String name = ""; int age = 0; while (reader.next() != null) { if (reader.fieldName().equals("name")) { reader.next(); name = reader.stringValue(); } else if (reader.fieldName().equals("age")) { reader.next(); age = reader.intValue(); } } System.out.println("Name: " + name); System.out.println("Age: " + age); reader.close(); } catch (IOException e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文