Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

How to Convert ResultSet Data into JSON Object.
Pls Help me.



Thanks
Sushant
Posted
Comments
thanh_bkhn 11-Oct-13 4:15am    
What are your data structure and your expected result?
Sushant Mandhare 11-Oct-13 4:17am    
Any data structure?
Take XYZ as example

Hi Sushant i have one solution for this problem. I think i will help you.


1)firs set the class path to gson-2.1.jar
2)code to conver the ResultSet object information to JSON .

ResultSet rSet=...

JsonObject jsonResponse = new JsonObject();
JsonArray data = new JsonArray();
while(rSet.next() ) {
JsonArray row = new JsonArray();
row.add(new JsonPrimitive(rSet.getString("columnName1")));
row.add(new JsonPrimitive(rSet.getString("columnName2")));
row.add(new JsonPrimitive(rSet.getString("columnName3")));

data.add(row);
}
jsonResponse.add("aaData", data);
 
Share this answer
 
JsonResult ResultSet=Json(customer, JsonRequestBehavior.AllowGet);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900