阿里fastjson 對象轉JSON

引入阿里fostjson庫

dependencies {
    compile 'com.alibaba:fastjson:1.2.23'
}

LoginBeen實體類

package com.example.scxx.scbluetoothpay.been;

import com.alibaba.fastjson.annotation.JSONType;

/**
 * FileName:LoginBeen
 * Description:
 * Company:上海XX信息
 * User:weijia
 * Email:[email protected]
 * Time: 2017-01-03 21:09
 * UpdateTime:
 */

@JSONType(orders = { "LoginName", "LoginPwd"})
public class LoginBeen {

    private String LoginName;

    private String LoginPwd;

    public void setLoginName(String LoginName){
        this.LoginName = LoginName;
    }
    public String getLoginName(){
        return this.LoginName;
    }
    public void setLoginPwd(String LoginPwd){
        this.LoginPwd = LoginPwd;
    }
    public String getLoginPwd(){
        return this.LoginPwd;
    }

}

//fastjson將實體類對象轉換爲JSON(loginUsername,loginUserpwd是獲取鍵盤錄入獲取的數據)

                    //fastjson將實體類對象轉換爲JSON
                    LoginBeen loginBeen = new LoginBeen();
                    loginBeen.setLoginName(loginUsername);
                    loginBeen.setLoginPwd(loginUserpwd);

                    String jsonstring = JSON.toJSONString(loginBeen);
                    System.out.println("jsonstring--------"+jsonstring);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章