이 기사에서는 참조를위한 JSON 처리 도구의 특정 코드를 공유합니다. 특정 내용은 다음과 같습니다
import java.io.ioexception; import java.util.date; java.util.hashmap import; java.util.map import; import javax.servlet.http.httpservletresponse; com.alibaba.fastjson.json import; com.alibaba.fastjson.serializer.serializerfeature import; /** * * @author humf * */public class fastjsonutil {/** * 객체 변환 json 문자열 * @param 객체 * @return */public static string tojsonstring (Object Object) {// disablecircularReferencedEtect는 원형 참조 감지 json.tojsongring (객체, serializerfeated); } // output JSON Public STATIC void write_json (httpservletResponse 응답, String JSonstring) {response.setContentType ( "Application/JSON; UTF-8"); 응답 .SetchAracterEncoding ( "UTF-8"); try {response.getwriter (). print (jsonstring); } catch (ioexception e) {e.printstacktrace (); }} / *** ajax 제출 후 콜백의 JSON 문자열* @return* / public static string ajaxresult (부울 성공, 문자열 메시지) {map map = new Hashmap (); map.put ( "success", success); // is map.put ( "message", message); // 문자 메시지 문자열 json = json.tojsonstring (map); json 리턴; } / *** JSON 문자열은 자동으로 접두사가 접두사로 표시됩니다* @Param JSON Original JSON String* @param prefix prefix* @return String* / public static String jsonformatteraddprefix (문자열 JSON, String Prefix, map <String, object> newMap) {if (newMap == null) {newMap = new Hashmap (); } map <string, object> map = (map) json.parse (json); for (문자열 키 : map.keyset ()) {Object Object = map.get (키); if (isentity (object)) {string jsonstring = json.tojsonstring (object); jsonformatteraddprefix (jsonstring, prefix+key+".", newMap); } else {newMap.put (prefix+key, object); }} return json.tojsonstring (newmap); } / ** * 개체가 엔티티인지 여부를 결정하십시오 * @param 객체 * @return * / private static boolean isentity (개체 객체) {if (개체 인스턴스 문자열) {return false; } if (개체 인스턴스 정수) {return false; } if (Object Incastof long) {return false; } if (java.math.bigdecimal의 개체 인스턴스) {return false; } if (객체 인스턴스의 날짜) {return false; } if (java.util.collection의 개체 인스턴스) {return false; } true를 반환합니다. }} 위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.