Skip to content

Instantly share code, notes, and snippets.

@yhishi
Last active September 25, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhishi/87e85f8e409c7706ef041f084ba01bab to your computer and use it in GitHub Desktop.
Save yhishi/87e85f8e409c7706ef041f084ba01bab to your computer and use it in GitHub Desktop.
gson.fromJson
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