Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Play-Json反序列化数据类型Map[X,List[Y]]_Json_Scala_Playframework 2.0 - Fatal编程技术网

Play-Json反序列化数据类型Map[X,List[Y]]

Play-Json反序列化数据类型Map[X,List[Y]],json,scala,playframework-2.0,Json,Scala,Playframework 2.0,我有一个变量,Map[models.Account,List[models.Journal\u Account]]type 我不知道如何反序列化该数据类型。我通常使用以下代码: implicit val Account_detailWrites: Writes[Account] = ( (JsPath \ "account_code").write[String] and (JsPath \ "account_name").write[String] and (JsPat

我有一个变量,
Map[models.Account,List[models.Journal\u Account]]
type

我不知道如何反序列化该数据类型。我通常使用以下代码:

implicit val Account_detailWrites: Writes[Account] = (
    (JsPath \ "account_code").write[String] and
    (JsPath \ "account_name").write[String] and
    (JsPath \ "account_type").write[Int] and
    (JsPath \ "description").write[String] and
    (JsPath \ "enable_payment").write[Boolean] and
    (JsPath \ "expense_claims").write[Boolean]
)(unlift(Account.unapply))

implicit val Account_detailReads: Reads[Account] = (
    (JsPath \ "account_code").read[String] and
    (JsPath \ "account_name").read[String] and
    (JsPath \ "account_type").read[Int] and
    (JsPath \ "description").read[String] and
    (JsPath \ "enable_payment").read[Boolean] and
    (JsPath \ "expense_claims").read[Boolean]
)(Account.apply _)
因为它有列表[Y],我不知道该怎么办。。有人能帮我吗

更新:

谢谢你们的回答,但我已经用jerkson创建了一个Json响应。。
例如:
Ok(generate(variable_name)).as(application/json)

首先,您需要为您的
模型定义
读取和
写入

e、 g

implicit val journalAccReads: Reads[JournalAccount] = ..
implicit val journalAccWrites: Writes[JournalAccount] = ...
然后

implicit val Account_detailReads: Reads[Account] = (
(JsPath \ "account_code").read[String] and
(JsPath \ "account_name").read[String] and
(JsPath \ "account_type").read[Int] and
(JsPath \ "description").read[String] and
(JsPath \ "enable_payment").read[Boolean] and
(JsPath \ "expense_claims").read[Boolean] and
(__ \ "journalAccounts").lazyRead(list[JournalAccount](journalAccReads)))
)(Account.apply _)
accountDetail
写入的类似条目


顺便说一句,Scala/Java推荐驼峰式
val
var
名称

您的问题是Json对象具有
String
键。游戏中的默认
读取
定义适用于
Map[String,V]
,其中
V
具有
读取[V]
,而不是任何
映射[K,V]
,即使
K
具有
读取[K]


您是否可以在
映射中返回
帐户名
,而不是整个
帐户

这在JSON中是什么样子?