问题
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