Cet article partage le code spécifique de l'outil de traitement JSON pour votre référence. Le contenu spécifique est le suivant
Importer java.io.ioException; Importer java.util.date; import java.util.hashmap; importation java.util.map; import javax.servlet.http.httpservletResponse; import com.alibaba.fastjson.json; import com.alibaba.fastjson.serializer.serializerfeature; / ** * * @Author Humf * * / public class FastJSonutil {/ ** * Convertir objet en json string * @param objet * @return * / public static string tojSontring (objet objet) {// DisablECircularReferendetect pour prohibit circulaire de détection de référence JSON.tojssentring (objet, sérializerfeate.DisabricarreCircularRefect); } // Sortie JSON public static void write_json (réponse httpservletResponse, string jSontring) {réponse.setContentType ("application / json; utf-8"); Response.SetcharAtterencoding ("UTF-8"); essayez {réponse.getWriter (). print (jSontring); } catch (ioException e) {e.printStackTrace (); }} / ** * JSON String of Rallback après la soumission Ajax * @return * / public static String ajaxResult (Boolean Success, String Message) {map map = new HashMap (); map.put ("succès", succès); // est map.put ("message", message); // chaîne de messages texte JSON = JSON.TojSontring (map); retourner JSON; }! } Map <string, objet> map = (map) json.parse (json); for (String Key: map.KeySet ()) {objet objet = map.get (key); if (isEntity (object)) {String jSontring = JSON.tojSontring (objet); JSONFormatterAddPrefix (JSontring, Prefix + Key + ".", Newmap); } else {newmap.put (préfixe + key, objet); }} return JSON.TojSontring (newmap); } / ** * Déterminez si un objet est une entité * @param objet * @return * / private static boolean isEntity (objet objet) {if (objet instance string) {return false; } if (objet instanceof Integer) {return false; } if (objet instanceof long) {return false; } if (objet instanceof java.math.bigdecimal) {return false; } if (objet instanceof date) {return false; } if (objet instanceof java.util.collection) {return false; } return true; }} Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.