Package com.wbm.app.utils;
Import com.wbm.app.business.model.BaseNotify;
Import org.json.JSONException;
Import Org.json.JSONObject;
Import Java.lang.reflect.Field;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Java.util.HashMap;
Import Java.util.Iterator;
/** * Created by the Administrator on 2016/10/11.
*/public class Hashmaputil {public static hashmap<string,string> Gethashmap (Object object,string classname) {
hashmap<string,string> map = new hashmap<string,string> (); try {class clazz = Class.forName (classname); to get its corresponding class object according to the class name just write the class name you want. Note is the full name if there is a package to add such as Java. Lang.string Object obj = clazz.newinstance ()//default objects created with the null parameter's construction method field[] fields = CLAZZ.GETDECLAREDF
Ields ()///String Key=null can also be obtained by acquiring property private based on the class object;
String value = null; for (Field f:fields) {//value = F.gettype (). GetName ();//print the type name of each property f.setaccessible (True);
Set some properties to be accessible object o = F.get (object);//print the type name of each property//Only when the value of the property is not empty.
if (o!=null) {value = O.tostring ();
Key = F.getname ();
Map.put (Key,value);
A catch (Exception e) {e.printstacktrace ());
} return map; public static hashmap<string,string> gethashmapformatdate (Object object,string classname) {hashmap< ;
string,string> map = new hashmap<string,string> (); try {class clazz = Class.forName (classname); to get its corresponding class object according to the class name just write the class name you want. Note is the full name if there is a package to add such as Java. Lang.string Object obj = clazz.newinstance ()//default objects created with the null parameter's construction method field[] fields = CLAZZ.GETDECLAREDF
Ields ()///String Key=null can also be obtained by acquiring property private based on the class object;
String value = null; for (Field f:fields) {//value = F.gettype (). GetName ();//PrintThe type name of each property f.setaccessible (true);
Set some properties to be accessible object o = F.get (object);//print the type name of each property//Only when the value of the property is not empty. if (o!=null) {//If the type is of type date, it is converted to java.util. The corresponding format String typename = F.gettype (). g
Etname ();
if ("Java.util.Date". Equals (typename)) {Date date = (date) O;
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String formateddate = Format.format (date);
value = Formateddate;
else value = o.tostring ();
Key = F.getname ();
Map.put (Key,value);
A catch (Exception e) {e.printstacktrace ());
} return map;
}
}