Dieser Artikel teilt den spezifischen Code des JSON -Verarbeitungstools für Ihre Referenz. Der spezifische Inhalt ist wie folgt
importieren java.io.ioException; import Java.util.date; import Java.util.hashMap; import Java.util.map; importieren javax.servlet.http.httpServletResponse; Import com.alibaba.fastjson.json; import com.alibaba.fastjson.serializer.SerializerFeature; /** * * @author humf * */ public class FastJsonUtil { /** * Convert object into json string* @param object * @return */ public static String toJSONString(Object object){ //DisableCircularReferenceDetect to prohibit circular reference detection return JSON.toJSONString(object,SerializerFeature.DisableCircularReferenceDetect); } // Ausgabe json public static void write_json (httpServletResponse-Antwort, String jSonstring) {response.setContentType ("application/json; utf-8"); response.setcharactercoding ("utf-8"); try {response.getWriter (). print (jSonstring); } catch (ioException e) {e.printstacktrace (); }} / *** JSON -Zeichenfolge nach AJAX -Einreichung* @return* / public static String ajaxResult (boolean erfolgreich, String -Nachricht) {map Map = new Hashmap (); map.put ("Erfolg", Erfolg); // ist map.put ("meldung", meldung); // Textnachricht String json = json.tojonstring (map); Rückkehr JSON; } /** * JSON string is automatically prefixed* @param json original json string* @param prefix prefix* @return String after prefix*/ public static String JsonFormatterAddPrefix(String json,String prefix,Map<String,Object> newmap) { if(newmap == null){ newmap = new HashMap(); } Map <string, object> map = (map) json.parse (json); für (String -Schlüssel: map.keyset ()) {Object Object = map.get (Schlüssel); if (isEntity (Objekt)) {String jSonstring = json.tojonstring (Objekt); JSONFORMATUMERADDPREFIX (JSONSTRING, PREFIX+KEY+".", Newmap); } else {newmap.put (Präfix+Schlüssel, Objekt); }} return json.tojonstring (newmap); } / ** * Bestimmen Sie, ob ein Objekt ein Entität ist * @param -Objekt * @return * / private statische boolesche Isentität (Objektobjekt) {if (ObjectinStanceof String) {return false; } if (Objektinstanz von Integer) {return false; } if (Objektinstanz lang) {return false; } if (Objektinstanz java.math.bigdecimal) {return false; } if (Objektinstanz von Datum) {return false; } if (Objektinstanz java.util.collection) {return false; } Return true; }} Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.