Last active
September 25, 2017 14:43
-
-
Save yhishi/87e85f8e409c7706ef041f084ba01bab to your computer and use it in GitHub Desktop.
gson.fromJson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.Gson; | |
/** | |
* 登録機能などでクライアント側からのJSON形式のデータを | |
* Javaオブジェクトに変換する | |
* ※inputは連想配列形式のJSONデータ | |
*/ | |
// 入力複数データをまとめて取得 | |
String input = request.getParameter("input"); | |
Gson gson = new Gson(); | |
// insdata[]クラスに変換(JSON⇒Javaオブジェクト) | |
insdata[] insdata = gson.fromJson(input,insdata[].class); | |
/** | |
* 別で定義する格納用クラス例 | |
*/ | |
public class insdata { | |
public String email = ""; | |
public String passwd = ""; | |
public String insdate = ""; | |
public String upddate = ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment