JAVA class to map tool class, network request inside use to __java

Source: Internet
Author: User
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&lt ;
        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;
 }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.