Convert from MySQL query result or LIST to JSON

空扰寡人 提交于 2019-12-11 11:27:04

问题


I am using anorm with play-scala and have execute queries using:

val result = SQL("SELECT * FROM users)()

What I have been doing is the following:

 val queryResult = SQL(query)().map(result =>
  result.asList
  ).toList

However, I have realized that instead of converting it to a list, I want to actually receive JSON. Since I may change the query, I would like the ability for a JSON serializer that takes in any result and understands the column names and convert them and the results into JSON.

EDIT: I'm using play 2.3.10 with scala version 2.11.6. I'm trying to map the SqlResult's metadata column names to an object or rather a json parser. I was able to get the SqlResult's metadata as

List(MetaDataItem(ColumnName(x),false, java.lang.Integer), MetaDataItem(ColumnName(y),.....

Thanks

来源:https://stackoverflow.com/questions/36484282/convert-from-mysql-query-result-or-list-to-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!