xstream - skriver json ved hjælp af xstream

, xstream støtter json, som starter xstream genstand med en passende chauffør.xstream i øjeblikket støtter jettisonmappedxmldriver og jsonhierarchicalstreamdriver. lad os prøve den kode med json håndtering i xstream. skabe en java - klasse fil, der hedder xstreamtester i, c: \\> xstream_workspace. kom. tutorialspoint. xstream,.,,, fil: xstreamtester. java, pakke com.tutorialspoint.xstream; import java.io.writer; import com.thoughtworks.xstream.xstream, import com.thoughtworks.xstream.annotations.xstreamalias; import com.thoughtworks.xstream.io.hierarchicalstreamwriter; import com.thoughtworks.xstream.io.json.jsonhierarchicalstreamdriver; import com.thoughtworks.xstream.io.json.jsonwriter; offentlige klasse xstreamtester {offentlige statisk tomrum vigtigste (string - args []) (xstreamtester tester = nye xstreamtester(); xstream xstream = nye xstream (nye jsonhierarchicalstreamdriver() {offentlige hierarchicalstreamwriter createwriter (forfatter forfatter) {tilbage nye jsonwriter (forfatter, jsonwriter. drop_root_mode)}}); studerende = nye studerende ("mahesh", "parashar"); xstream. setmode (xstream. no_references); xstream. alias ("studerende". studerende. klasse) system. println (xstream. toxml (studerende)}} @ xstreamalias ("studerende") klasse elev (private snor firstname; private snor lastname; offentlige studerende (string firstname, snor lastname) (this.firstname = firstname. this.lastname = lastname;} offentlige snor getfirstname() {tilbage førstnavn} offentlige snor getlastname() {tilbage lastname;} offentlige snor tostring() {tilbage "elev [firstname:" + firstname + ", lastname:" + lastname + "]"}}, kontrollere resultatet, udarbejder klasser med, javac, compiler som følger: c: xstream_workspace. kom. det tutorialspoint. xstream> javac xstreamtester.java, nu kører det xstreamtester se resultatet: c:. xstream_workspace. kom. tutorialspoint. xstream> java xstreamtester, verificere output som følger:,, ("firstname": "mahesh", "lastname": "parashar"), og



Previous:
Next Page: