1. The first way to implement the Jsonstring interface method
Public class Implements jsonstring { private String name; Private String age; Private address address; // Getters & Setters Public return "{name: '" +name+ "', Age: '" +age+ "'}";}
}
Public classTest { Public Static voidMain (string[] args) {Person person =New Person ("Xxb", "+");
System.out.println (jsonobject.fromobject(person). toString ()); }}
2. The second way, through the Jsonconfig instance, the inclusion and the need to exclude the attributes to be easily added or removed (establish jsonconfig instance, and configure the attribute exclusion list)
public class person { private String name; private String age; private address address; // getters & setters }
Public class Test { publicstaticvoid main (string[] args) { new Person ("XXB", "+"); New jsonconfig (); New string[]{"Address"}); System.out.println (Jsonobject.fromobject (person,jsonconfig). toString ()); } }
Jsonobject and Jsonarray use 3--java object property additions or deletions (jsonconfig)