Last active
September 25, 2017 14:42
-
-
Save yhishi/e028e30e5ef59cf748de7183b5a820a6 to your computer and use it in GitHub Desktop.
gson.toJson
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; | |
/** | |
* 検索機能などでDBから値を取得し、クライアント側にリストを返すとき、 | |
* Javaオブジェクトでは返せないため、JSON形式に変換する | |
* ※dblistはDBから取得した<ArrayList<String>> | |
*/ | |
// Gsonオブジェクトを作成 | |
Gson gson = new Gson(); | |
// クライアントにDBからのデータリストを返す | |
PrintWriter out = response.getWriter(); | |
// (Javaオブジェクト⇒JSON) | |
out.println(gson.toJson(dblist)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment