vendredi 17 novembre 2017

JSON construcation from mysql Query

A Group by query gives this result from which i want to get the following json which produces a tree like chart:

Count | ApplicationStatus | Gender | Consent | Admitted

 71   Confirmed            Male     Submitted              0   
236   Confirmed            Male     Not Submitted          0  
  5   Confirmed            Male     Submitted              1 
782   Confirmed            Male     null                   0   
742   Confirmed            Male     null                   1  
  5   Confirmed            Male     Not Submitted          1  
235   Confirmed            Female   Submitted              0  
502   Confirmed            Female   null                   0  
563   Confirmed            Female   Not Submitted          0  
 17   Confirmed            Female   Submitted              1  
886   Confirmed            Female   null                   1  
 22   Confirmed            Female   Not Submitted          1  
 13   Unconfirmed          Male     Submitted              0  
594   Unconfirmed          Male     null                   0  
 81   Unconfirmed          Male     Not Submitted          0  
329   Unconfirmed          Male     null                   1  
 20   Unconfirmed          Female   Submitted              0    
428   Unconfirmed          Female   null                   0  
113   Unconfirmed          Female   Not Submitted          0  
  1   Unconfirmed          Female   Submitted              1  
284   Unconfirmed          Female   null                   1  

Right now, I use parse the resultset (in JAVA) row by row and using a nest if elses, I generate the JSON. If i need to change something, it is really tricky to keep track of all the conditons and apply the desired changes correctly. Just wanted to check if there is any other simpler approach to solve this problem? Any help?

Aucun commentaire:

Enregistrer un commentaire