Created
June 25, 2016 13:39
-
-
Save sharif2008/9139dc56f6605a7ed2233d23deb5bcf9 to your computer and use it in GitHub Desktop.
Get JSON response of multiple Array
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package gsontest; | |
import java.util.ArrayList; | |
/** | |
* | |
* @author sharif | |
*/ | |
import com.google.gson.Gson; | |
import com.google.gson.JsonObject; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class GSONofMultipleArray { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
ArrayList<Object> allList = new ArrayList<>(); | |
ArrayList<Object> jarrayTable = new ArrayList<Object>(); | |
ArrayList<Object> jarrayChartTotalMF = new ArrayList<Object>(); | |
ArrayList<Object> jarrByAgeGroup = new ArrayList<Object>(); | |
JsonObject objTotal = new JsonObject(); | |
allList.add(objTotal); | |
allList.add(jarrayTable); | |
allList.add(jarrayChartTotalMF); | |
allList.add(jarrByAgeGroup); | |
String allJSON = new Gson().toJson(allList); | |
System.out.println(allJSON); | |
//Or | |
HashMap<String, Object> allList2 = new HashMap(); | |
allList2.put("obj", objTotal); | |
allList2.put("arr1", jarrayTable); | |
allList2.put("arr2", jarrayChartTotalMF); | |
allList2.put("arr3", jarrByAgeGroup); | |
String allJSON2 = new Gson().toJson(allList2); | |
System.out.println(allJSON2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment