<dependency> \t<groupId>org.hjson</groupId> \t<artifactId>hjson</artifactId> \t<version>3.0.0</version> </dependency> import org.hjson.JsonObject; import org.hjson.JsonValue; import org.hjson.JsonObject.Member; public class HjsonReaderExample { \tpublic static void main(String[] args) { \t\tString hjsonData = "{\r " + " + \t\t\t\t" \"name\": \"John\",\r " + \t\t\t\t" \"age\": 30,\r " + \t\t\t\t" \"city\": \"New York\"\r " + \t\t\t\t"}"; \t\tJsonValue hjson = org.hjson.Hjson.parse(hjsonData); \t\tJsonObject obj = hjson.asObject(); \t\tfor (Member member : obj) { \t\t\tSystem.out.println(member.getName() + ": " + member.getValue().asString()); \t\t} \t} } import org.hjson.JsonObject; public class HjsonWriterExample { \tpublic static void main(String[] args) { \t\tJsonObject hjsonObject = new JsonObject(); \t\thjsonObject.add("name", "John"); \t\thjsonObject.add("age", 30); \t\thjsonObject.add("city", "New York"); \t\tString hjsonString = hjsonObject.toString(); \t\tSystem.out.println(hjsonString); \t} }


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