これに対する答えがわかりません - これを行う簡単な方法はありますか? いくつかのオブジェクト x のリストを取得し、ハッキーなコードなしで単一の json オブジェクトに変換したいですか? 私はいくつかの醜いことをしていましたが、このリストを「データ」と呼ばれるオブジェクトに入れたいと思っています。これをどうにかしてオブジェクト「データ」にマップできますか?
private def renderArticleJson(articles: Iterable[GraphedArticle]): String = {
val listToConvert = for (article <- articles) yield {
JsObject(
"articleId" -> Json.toJson(article.getArticleId)
:: "articleUrl" -> Json.toJson(article.getArticleUrl)
:: "graphId" -> Json.toJson(article.asVertex().getId.toString)
:: "fullName" -> Json.toJson(article.getTitle)
:: "imageUrl" -> Json.toJson(article.getImageUrl)
:: Nil
)
}
}
要求に応じて編集:私が得たいものを追加しました(最初の回答の助けのおかげで解決しました)
{
"data": [
{
"articleId": null,
"articleUrl": null,
"graphId": "#8:24",
"fullName": "hey",
"imageUrl": "hey"
},
{
"articleId": null,
"articleUrl": null,
"graphId": "#8:25",
"fullName": "hey",
"imageUrl": "hey"
},
{
"articleId": "b23c162d-b0af-4ce3-aebf-f33943492f95",
"articleUrl": null,
"graphId": "#8:26",
"fullName": "hey",
"imageUrl": "hey"
},
{
"articleId": "8afe310c-8337-4a8a-8406-5670249ba0a7",
"articleUrl": "hey",
"graphId": "#8:27",
"fullName": "hey",
"imageUrl": "hey"
}
]
}