Java-如何将数据从mysql数据库转换为JSON数组? [英] Java - How to convert data from mysql database to a JSON Array?
本文介绍了Java-如何将数据从mysql数据库转换为JSON数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个mysql数据库,其中的"trips"表带有一些列,看起来像这样:
I have a mysql database with the table "trips" with some columns, it looks like this:
每行包含一次旅行的数据.我想搜索"asg_id",并希望获得所有带有"asg_id"的行(行程).
Each row contains the data for one trip. And I want to search for the "asg_id" and want to get all rows(trips) with this "asg_id" .
我的问题是,如何通过JSON数组的单个行程转换此数据?或者,如何使用此"asg_id"获得所有旅程?
My question is, how to convert this data with the individual trips tho a JSON Array? Or, how can I get all trips with this "asg_id"?
推荐答案
JSONObject json = new JSONObject();
json .put("json", collection/object);
request.setAttribute("jsonObject", json.toString());
这篇关于Java-如何将数据从mysql数据库转换为JSON数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文