Sort JsonArray by variable key using GSON - java

I am trying to sort a JsonArray in Java using GSON, I would like to sort everything inside that array via a variable key, meaning there is a string somewhere containing something that is the key that the object needs to be sorted by.
Key Variable: varkey1
[{"varkey1":1,"othervarkey":1},{"varkey1":6,"othervarkey":2},{"varkey1":3,"othervarkey":3},{"varkey1":12,"othervarkey":4},{"varkey1":998,"othervarkey":5}]
So it should go like like:
[{"varkey1":1,"othervarkey":1},{"varkey1":3,"othervarkey":2},{"varkey1":6,"othervarkey":3},{"varkey1":12,"othervarkey":4},{"varkey1":998,"othervarkey":5}]

Well, you could just implement a sorting algorithm that could be specialized for Gson JsonElements.
If not, you could just re-use standard Collections.sort(...) that can merely do the job for you.
For some reason, JsonArray implements Iterable and not List where the latter can be sorted with Collection.sort.
So, a custom JsonArray-to-List is required:
final class JsonArrayList
extends AbstractList<JsonElement> {
private final JsonArray jsonArray;
private JsonArrayList(final JsonArray jsonArray) {
this.jsonArray = jsonArray;
}
static List<JsonElement> of(final JsonArray jsonArray) {
return new JsonArrayList(jsonArray);
}
// This method is required when implementing AbstractList
#Override
public JsonElement get(final int index) {
return jsonArray.get(index);
}
// This method is required when implementing AbstractList as well
#Override
public int size() {
return jsonArray.size();
}
// And this one is required to make the list implementation modifiable
#Override
public JsonElement set(final int index, final JsonElement element) {
return jsonArray.set(index, element);
}
}
Now, the rest is simple:
// No even need of Gson instantiation
final JsonArray jsonArray = new JsonParser()
.parse(jsonReader)
.getAsJsonArray();
// Create a JsonArray to a List view instance
final List<JsonElement> jsonElements = JsonArrays.asList(jsonArray);
// Sorting the jsonElements object
Collections.sort(jsonElements, (e1, e2) -> {
final int i1 = e1.getAsJsonObject().get("varkey1").getAsInt();
final int i2 = e2.getAsJsonObject().get("varkey1").getAsInt();
return Integer.compare(i1, i2);
});
Since the jsonElements is just a view for jsonArray, jsonArray is actually sorted.

Try the following:-
String jsonListString = "[{\"varkey1\":1,\"othervarkey\":1},{\"varkey1\":6,\"othervarkey\":2},{\"varkey1\":3,\"othervarkey\":3},{\"varkey1\":12,\"othervarkey\":4},{\"varkey1\":998,\"othervarkey\":5}]";
JSONArray jsonArray = new JSONArray(jsonListString);
// Create Java ArrayList from JSON Array
ArrayList<JSONObject> array = new ArrayList<JSONObject>();
for (int i = 0; i < jsonArray.length(); i++) {
try {
array.add(jsonArray.getJSONObject(i));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Sort the Java Array List
Collections.sort(array, new Comparator<JSONObject>() {
#Override
public int compare(JSONObject lhs, JSONObject rhs) {
// TODO Auto-generated method stub
try {
return (lhs.getInt("varkey1").compareTo(rhs.getInt("varkey1")));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
});
// convert Java Array List to JSON Array and then to String representation.
jsonArray = new JSONArray(array);
jsonListString = jsonArray.toString();
This code:-
Creates JSONArray from String.
Creates Java ArrayList from JSONArray.
Sort Java ArrayList using Collections.sort()
Then Create JSONArray from Java ArrayList.
Then return JSONArray as JSON String representation.

This will return the sorted json. Used the gson library.
pass the Args: 1. jsonArray, 2. "othervarkey"
private static JsonArray JsonObjectSort(final JsonArray jsonArray, final String sortBy) {
final JsonArray sortedArray = new JsonArray();
final ArrayList<JsonObject> listJsonObj = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
listJsonObj.add((JsonObject) jsonArray.get(i));
}
Collections.sort(listJsonObj,
(o1, o2) -> o1.get(sortBy).getAsString().compareToIgnoreCase(o2.get(sortBy).getAsString()));
for (int i = 0; i < jsonArray.size(); i++) {
sortedArray.add(listJsonObj.get(i));
}
return sortedArray;
}

Related

Guava Hashmap comparison

I'm having some trouble using Guava's Maps.difference
Right now, using this code to compare two HashMaps from two different jsons:
//Create maps from the given jsons
Gson gson = new Gson();
Type type = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> map1 = gson.fromJson(jsonObject1, type);
Map<String, Object> map2 = gson.fromJson(jsonObject2, type);
//Flatten the maps
Map<String, Object> leftFlatMap = FlatMap.flatten(map1);
Map<String, Object> rightFlatMap = FlatMap.flatten(map2);
//Check differences between both maps
MapDifference<String, Object> difference = Maps.difference(leftFlatMap, rightFlatMap);
Everything works fine, and compares (almost) all the elements correctly.
Problem is when one of the elements inside the HashMap is an array of maps and the elements are the same but in a different order. Like this:
FIRST JSON:
{ "body":[
{
"primitive":"VALUE",
"jsonArray":[
{
"element":83284180
},
{
"anotherElement":20832841804
}
]
}
]
}
SECOND JSON:
{
"body":[
{
"primitive":"VALUE",
"jsonArray":[
{
"anotherElement":20832841804
},
{
"element":83284180
}
]
}
]
}
As you can see, element and anotherElement values are the same but as they appear in a different order inside the array, difference shows an error.
Is there any possibility to sort the array before? or any other solution?
Thanks in advance!!
One of possible solutions may be sorting the inner sub array so that it would affect the deserialized maps (however, I think making maps out of JSON objects in this case might be a not very good idea due to deserialization costs and strategies that do not necessarily represent the original JSON object).
Assuming jsonObject1 and jsonObject2 are JsonElement implementations, you can sort its descendants.
#UtilityClass
public final class JsonElements {
public static List<JsonElement> asListView(final JsonArray jsonArray) {
return new JsonArrayListView(jsonArray);
}
public static void sort(final JsonArray jsonArray, final Comparator<? super JsonElement> comparator) {
Collections.sort(asListView(jsonArray), comparator);
}
#AllArgsConstructor(access = AccessLevel.PRIVATE)
private static final class JsonArrayListView
extends AbstractList<JsonElement> {
private final JsonArray jsonArray;
#Override
public JsonElement get(final int index) {
return jsonArray.get(index);
}
#Override
public int size() {
return jsonArray.size();
}
#Override
#SuppressWarnings("MethodDoesntCallSuperMethod")
public JsonElement set(final int index, final JsonElement element) {
return jsonArray.set(index, element);
}
}
}
public final class JsonElementsTest {
private static final Gson gson = new GsonBuilder()
.disableHtmlEscaping()
.disableInnerClassSerialization()
.create();
private static final Type stringToObjectMapType = new TypeToken<Map<String, Object>>() {}.getType();
#Test
public void testSort()
throws IOException {
final JsonElement jsonElement1 = ... read the 1st JSON document ...;
final JsonElement jsonElement2 = ... read the 2nd JSON document ...;
final JsonArray jsonSubArray1 = getSubArray(jsonElement1);
final JsonArray jsonSubArray2 = getSubArray(jsonElement2);
Assertions.assertNotEquals(jsonSubArray1, jsonSubArray2);
JsonElements.sort(jsonSubArray1, JsonElementsTest::compare);
JsonElements.sort(jsonSubArray2, JsonElementsTest::compare);
final Map<String, Object> map1 = gson.fromJson(jsonElement1, stringToObjectMapType);
final Map<String, Object> map2 = gson.fromJson(jsonElement2, stringToObjectMapType);
Assertions.assertEquals(map1, map2);
}
private static JsonArray getSubArray(final JsonElement jsonElement) {
return jsonElement.getAsJsonObject()
.get("body")
.getAsJsonArray()
.get(0)
.getAsJsonObject()
.get("jsonArray")
.getAsJsonArray();
}
private static int compare(final JsonElement jsonElement1, final JsonElement jsonElement2)
throws IllegalArgumentException {
final JsonObject jsonObject1 = jsonElement1.getAsJsonObject();
final int size1 = jsonObject1.size();
if ( size1 != 1 ) {
throw new IllegalArgumentException("Size-1 must equal 1, but was " + size1);
}
final JsonObject jsonObject2 = jsonElement2.getAsJsonObject();
final int size2 = jsonObject2.size();
if ( size2 != 1 ) {
throw new IllegalArgumentException("Size-2 must equal 2, but was " + size2);
}
// TODO optimize somehow
final String key1 = jsonObject1.keySet().iterator().next();
final String key2 = jsonObject2.keySet().iterator().next();
return key1.compareTo(key2);
}
}
Also consider sorting the descendants recursively if necessary.
Note that you also might have a mapping for the given JSON documents, but I don't think it's your case, but if it is, then you might want to apply #JsonAdapter to apply a special ordering deserializer (however I still don't think it's a good idea too). Or else, it is also possible to create a map view for the given JsonObjects so that it might produce recursive reordering views.

Rewrite Iterator from JSONObject to JSONArray

I have an iterator for JSONObjects but unfortunately I get a JSONArray from my JSON-data.
Now I want to rewrite it. I'm pretty new to Java. Can somebody tell me how to approach this?
I use the json.simple library.
public class JSONIteratorAuthor implements Iterator <Author> {
private Iterator<JSONObject> authors;
public JSONIteratorAuthor(JSONObject jsonObject){
this.authors = ((JSONArray) jsonObject.get("authors")).iterator();
}
#Override
public boolean hasNext() {
return this.authors.hasNext();
}
public Author next() {
if(this.hasNext()){
Author a = new Author(0, "", "");
JSONObject authorNode = (JSONObject) authors.next();
a.setFirstName((String) authorNode.get("first_name"));
a.setLastName((String) authorNode.get("last_name"));
return a;
}
else {
return null;
}
}
}
Due to lack of information about the structure of your JSON data, I assume the following:
You have got a JSONArray object to call the constructor with
This JSONArray contains JSONObjects
These JSONObjects have got suitable key-value pairs
In that case the following solution should work. It takes advantage of the fact that JSONArray itself is iteratable.
private Iterator<JSONObject> authors;
#SuppressWarnings("unchecked")
public JSONIteratorAuthor(JSONArray array){
authors = array.iterator();
}
#Override
public boolean hasNext() {
return authors.hasNext();
}
#Override
public Author next() {
if (hasNext()) {
Author a = new Author(0, "", "");
JSONObject authorNode = authors.next();
a.setFirstName((String) authorNode.get("first_name"));
a.setLastName((String) authorNode.get("last_name"));
return a;
}
else {
return null;
}
}
EDIT: Given your actual input, the solution is simple: The array contains objects, which contain yet other arrays. So for the above code to work, you have to do the following (where parsedJson is that, what you get from your actual input file (as posted in dropbox):
Iterator array = ((JSONArray) parsedJson).iterator();
while (array.hasNext()) {
JSONObject json = (JSONObject) array.next();
JSONArray authors = (JSONArray)json.get("authors");
JSONIteratorAuthor test = new JSONIteratorAuthor(authors);
while (test.hasNext()) {
System.out.println(test.next());
}
}

Java - Make a library class comparable

Is it possible to make library classes comparable without extending them?
import org.json.JSONObject;
LinkedList<JSONObject> list = getListFromFunction();
TreeSet<JSONObject> treeSet = new TreeSet<JSONObject>(list);
Making a TreeSet here is not possible as JSONObject is not comparable. How can I "attach" a custom comparator to JSONObject? (There is a unique property, say "_some_id" to compare with)
We can use Comparator in such a case and handle the scenario. Please refer the below example.
Main Class
public class ComparatorTest{
public static void main(String[] ar) {
// System.out.println(new Sample().stringTimes("vivek", 5));
JSONObject emp1 = new JSONObject();
JSONObject emp2 = new JSONObject();
try {
emp1.put("department", "IT");
emp1.put("name", "bvivek");
emp1.put("id", 1);
emp2.put("department", "IT");
emp2.put("name", "avikash");
emp2.put("id", 2);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<JSONObject> employess = new ArrayList<JSONObject>();
employess.add(emp1);//add to list
employess.add(emp2);//add to list
System.out.println(employess);//unsorted, as is
Collections.sort(employess, new JSONComparator("name"));
System.out.println(employess);//sorted as per the field
//using treeSet
TreeSet<JSONObject> jsonInTree = new TreeSet<JSONObject>(new JSONComparator("id"));
jsonInTree.addAll(employess);
System.out.println(jsonInTree);//using the tree implementation
}
}
JSONComparator
class JSONComparator implements Comparator<JSONObject> {
private String fieldToCompare;
public JSONComparator(String fieldToCompare) {
this.fieldToCompare = fieldToCompare;
}
#Override
public int compare(JSONObject o1, JSONObject o2) {
String id1 = "";
String id2 = "";
try {
id1 = o1.getString(this.fieldToCompare);
id2 = o2.getString(this.fieldToCompare);
} catch (JSONException e) {
}
return id1.compareTo(id2);
}
}
The simplest way to do something like this will work for any classes that aren't comparable. The way you do this is by creating your own comparing method, you can do this in a way like:
public static int compareJSONObjects(JSONObject obj1, JSONObject obj2){
if(obj1.getField()>obj2.getField()){
return 1;
}else{
return -1;
}
}
now when you call list.sort() you can create your own Comparator like this:
list.sort( (obj1, obj2) -> compareJSONObject(obj1, obj2) );
by doing this you cut down on the amount of lines required, as this entire thing could be shortened to 1 line by using ternary and doing:
list.sort( (obj1, obj2) -> obj1.getField()>obj2.getField() ? 1 : -1 );

Arraylist Value object added to the JSON While using GSON

Hi in my app i am using to create a JSON string. So i thought of using GSON. I have two function one is to store the arraylist and another is normal object. My problem is the ArrayList part is working fine but when i print the normal object function the arraylist object is added to the json part here is my coding
main class
JsonStructure json = new JsonStructure();
json.messages.add("msg 1");
json.messages.add("msg 2");
json.messages.add("msg 3");
json.asecs.add("asec 1");
json.asecs.add("asec 2");
json.asecs.add("asec 3");
Gson gson = new Gson();
output = gson.toJson(json);
Log.i("gson", output);
List<JsonStructure> Allergylist = new ArrayList<JsonStructure>();
for (int i = 0; i < 5; i++) {
JsonStructure oAllergy_Data = new JsonStructure();
oAllergy_Data.setIdmember("hi");
oAllergy_Data.setIduser("hello");
// Adding register to list
Allergylist.add(oAllergy_Data);
}
Gson newgson = new Gson();
String newoutput = newgson.toJson(Allergylist);
Log.i("gson new", newoutput);
and here is my object class
public class JsonStructure {
String idpeople;
String iduser;
String idmember;
ArrayList<String> messages = new ArrayList<String>();
ArrayList<String> asecs = new ArrayList<String>();
public JsonStructure() {
}
public String getIdpeople() {
return idpeople;
}
public void setIdpeople(String idpeople) {
this.idpeople = idpeople;
}
public String getIduser() {
return iduser;
}
public void setIduser(String iduser) {
this.iduser = iduser;
}
public String getIdmember() {
return idmember;
}
public void setIdmember(String idmember) {
this.idmember = idmember;
}
public ArrayList<String> getMessages() {
return messages;
}
public void setMessages(ArrayList<String> messages) {
this.messages = messages;
}
public ArrayList<String> getAsecs() {
return asecs;
}
public void setAsecs(ArrayList<String> asecs) {
this.asecs = asecs;
}
}
my out put that look like
gson(21917): {"asecs":["asec 1","asec 2","asec 3"],"messages":["msg 1","msg 2","msg 3"]}
gson new(21917): [{"asecs":[],"idmember":"hi","iduser":"hello","messages":[]},{"asecs":[],"idmember":"hi","iduser":"hello","messages":[]},{"asecs":[],"idmember":"hi","iduser":"hello","messages":[]},{"asecs":[],"idmember":"hi","iduser":"hello","messages":[]},{"asecs":[],"idmember":"hi","iduser":"hello","messages":[]}]
my out put should look like
gson new(21917): [{"idmember":"hi","iduser":"hello"},{"idmember":"hi","iduser":"hello"},{"idmember":"hi","iduser":"hello"},{"idmember":"hi","iduser":"hello"},{"idmember":"hi","iduser":"hello"}]
my question is
1)If the gson will display all the object that declare in the class then why the idpeople is not display only arraylist is displayed to my json
2)Should i need to create a separate object file for the Arraylist or any alter coding for my coding
whatever the JsonStructure will contain, all that will be part of your json. if you dont want to include it in your json remove it from class.
I personally think it is not going to harm anyone if your json will contain any extra field and that field is useful for you.
Creating an new class -
JsonStructure oAllergy_Data = new JsonStructure();
will allow your arraylist to be a part of your json. if you dont want it to include, make it separate from JsonStructure class.
Or As an alternative Json can be created like this -
JSONObject outer = new JSONObject();
try {
// field
outer.put("EMAIL", reqModel.getEmail());
// field
outer.put("PASSWORD", reqModel.getPassword());
} catch (JSONException e) {
//
} catch (Exception e) {
//
}
return outer.toString();
remove this line
ArrayList<String> messages = new ArrayList<String>();
ArrayList<String> asecs = new ArrayList<String>();
Use
ArrayList<String> messages ;
ArrayList<String> asecs;
only

Converting the Database details to JSON object

I have a table with has the columns namely
recordID, recordName , titleFeild, titleIDMap, titleId, titleStartDate, titleEndDate, languageId
Now I have convert the data from above columns to the JSON object data which looks like below
{
"recordId" :10,
"recordName" : "RECORDS",
"records" : [ {
"titleField" : 1,
"titleIDMap" : null,
"titleId" : 500,
"titleStartDate" : "2013-12-22T00:00:00.000+0000",
"titleEndDate" : "2013-12-03T00:00:00.000+0000",
"languageId" : 20
}]
}
Please note that records is an array of columns ( titleFeild,titleIDMap,titleId,titleStartDate,titleEndDate,languageId)
The code so far I have developed is
List<Object[]> objList = dao.getStatus();
Integer result = null;
JSONObject jsonData = new JSONObject();
JSONArray jsonDataArray = new JSONArray();
if(objList!=null && objList.size()>10000)
{
for (Object[] nameObj : objList) {
jsonData.put("", nameObj.get(arg0) );
}
}
How do I construct the JSON Object from the columns data ?
You can easily achieve this with google-gson library. In simple terms you would have to create a couple of Pojos (with reference to another containin a list of references).
Consider RecordID and RecordName as Meta Data.
Create a pojo representing this information:
public class DbMetaPojo {
private int recordID;
private String recordName;
private List<Record> records;
public List<Record> getRecords() {
return records;
}
public void setRecords(List<Record> records) {
this.records = records;
}
public String getRecordName() {
return recordName;
}
public void setRecordName(String recordName) {
this.recordName = recordName;
}
public int getRecordID() {
return recordID;
}
public void setRecordID(int recordID) {
this.recordID = recordID;
}
}
Create another pojo with the actual Record fields:
public class Record {
public int getTitleFeild() {
return titleFeild;
}
public void setTitleFeild(int i) {
this.titleFeild = i;
}
public String getTitleIDMap() {
return titleIDMap;
}
public void setTitleIDMap(String titleIDMap) {
this.titleIDMap = titleIDMap;
}
public int getTitleId() {
return titleId;
}
public void setTitleId(int titleId) {
this.titleId = titleId;
}
public String getTitleStartDate() {
return titleStartDate;
}
public void setTitleStartDate(String titleStartDate) {
this.titleStartDate = titleStartDate;
}
public String getTitleEndDate() {
return titleEndDate;
}
public void setTitleEndDate(String titleEndDate) {
this.titleEndDate = titleEndDate;
}
public int getLanguageId() {
return languageId;
}
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
private int titleFeild;
private String titleIDMap;
private int titleId;
private String titleStartDate;
private String titleEndDate;
private int languageId;
}
Now just a method to populate your POJOs with the relevant data (replace the hardcoding logic with your data retrieve):
public static void main(String... main) {
DbMetaPojo obj = new DbMetaPojo();
obj.setRecordID(10);
obj.setRecordName("RECORDS");
Record record = new Record();
record.setLanguageId(20);
record.setTitleEndDate("2013-12-22T00:00:00.000+0000");
record.setTitleFeild(1);
record.setTitleId(500);
record.setTitleIDMap("SOME NULL");
record.setTitleStartDate("2013-12-22T00:00:00.000+0000");
List<Record> list = new ArrayList<Record>();
list.add(record);
obj.setRecords(list);
Gson gson = new Gson();
String json = gson.toJson(obj);
System.out.println(json);
}
Output is your formed JSON:
{
"recordID": 10,
"recordName": "RECORDS",
"records": [
{
"titleFeild": 1,
"titleIDMap": "SOME NULL",
"titleId": 500,
"titleStartDate": "2013-12-22T00:00:00.000+0000",
"titleEndDate": "2013-12-22T00:00:00.000+0000",
"languageId": 20
}
]
}
EDIT:
To align to your code, you might want to do something like:
List<Object> objList = dao.getStatus();
List<DbMetaPojo> metaList = new ArrayList<DbMetaPojo> ();
if (objList != null && objList.size() > 10000) {
for (Object nameObj : objList) {
DbMetaPojo meta = new DbMetaPojo();
meta.setRecordID(nameObj[0]);
meta.setRecordName(nameObj[0]);
...
...
...
metaList.add(meta);
}
}
First of all what you have to do is retrieve the data from the columns of the table using your DAO and calling a Function from DAOIMPL which in turn will return the list of data(POJO probably).
Create a map like this which will contain your key value pair for example recordid and value,
recordname and value
Map<String,Object> objMap = new HashMap<String,Object>();
objMap.put("recordId", Record.getId());
objMap.put("recordName",Record.getName());
// Now here is the deal create another hashmap here whose key will be records "the key for your second array"
//Put the values in this second hashmap as instructed above and put it as a key value pair.
........
.......
.......
JSONObject JsonObject = JSONObject.fromObject(objMap);//This will create JSON object out of your hashmap.
objJSONList.add(JsonObject);
}
StringBuffer jsonBuffer = new StringBuffer();
jsonBuffer.append("{\"data\": {");
jsonBuffer.append(objJSONList.tostring());
jsonBuffer.append("}");
//jsonBuffer.append(",\"total\":"+ objJSONList.size());// TOTAL Optional
//jsonBuffer.append(",\"success\":true}");//SUCCESS message if using in callback Optional
Create an object which has your attribues. (recordID, recordName , titleFeild, titleIDMap, titleId, titleStartDate, titleEndDate, languageId)
Get data from dao and convert it to json. It will looks like what you want.
Gson gson = new Gson();
// convert java object to JSON format,
// and returned as JSON formatted string
String json = gson.toJson(obj);
I think your dao.getStatus() should return a List with Map keys and values. Your key would be column name and value would be content.
List<Map<String,Object>> objList = dao.getStatus();
if(objList!=null && objList.size()>10000){
for(Map<String,Object> row : objList) {
Iterator<String> keyList = row.keySet().iterator();
while(keyList.hasNext()){
String key = keyList.next();
jsonData.put(key, row.get(key));
}
}
}
For the records array you need to build it while iterating table columns.
Combining above code with building records array would be something like this..
String[] group = {"titleField","titleIDMap","titleId","titleStartDate","titleEndDate","languageId"};
List<String> recordGroup = Arrays.asList(group);
Map<Object, JSONArray> records = new HashMap<Object,JSONArray>();
List<Map<String,Object>> objList = dao.getStatus();
JSONObject jsonData = new JSONObject();
if(objList!=null && objList.size()>10000){
for(Map<String,Object> row : objList) {
int columnCount = 0;
Iterator<String> keyList = row.keySet().iterator();
while(keyList.hasNext()){
String key = keyList.next();
if(recordGroup.contains(key)){
Object recordId = row.get("recordId");
JSONArray recordArray = new JSONArray();
if(records.containsKey(recordId)){
recordArray = records.get(recordId);
JSONObject jsonObj = null;
if(columnCount >= recordGroup.size()){
jsonObj = new JSONObject();
recordarray.add(jsonObj);
columnCount = 0;
}
else {
jsonObj = (JSONObject) recordArray.get(recordArray.size()-1);
}
jsonObj.put(key, row.get(key));
columnCount++;
}
else {
JSONObject jsonObj = new JSONObject();
jsonObj.put(key, row.get(key));
recordArray.add(jsonObj);
records.put(recordId, recordArray);
}
jsonData.put("records", records.get(recordId));
}
else {
jsonData.put(key, row.get(key));
}
}
}
}

Categories

Resources