play框架中ListBuffer[(字符串,字符串)]的json反序列化

play框架中ListBuffer[(字符串,字符串)]的json反序列化,json,scala,playframework,playframework-2.1,playframework-2.2,Json,Scala,Playframework,Playframework 2.1,Playframework 2.2,我正在用scala中的play框架开发应用程序,我想要json中的响应,但编译时错误即将出现 No Json deserializer found for type List[(String, String)]. Try to implement an implicit Writes or Format for this type. 列表缓冲区是 ListBuffer((This,a choke), (a Cv,15.6 gal)) 我也这样做了 Json.toJson(list)) 但

我正在用scala中的play框架开发应用程序,我想要json中的响应,但编译时错误即将出现

 No Json deserializer found for type List[(String, String)]. Try to implement an implicit Writes or Format for this type.
列表缓冲区是

ListBuffer((This,a choke), (a Cv,15.6 gal))
我也这样做了

Json.toJson(list))
但还是有错误


任何人都能给我一些解决这个问题的想法。

你希望它是什么json表示的
(String,String)
? 如果是这样的话:

yourListName : {
  "1" : "2",
  "3" : "4"
}
implicit val writer = new Writes[(String, String)] {
    def writes(c: (String, String)): JsValue = {
      Json.obj("something" -> c._1 + ", " + c._2)
      //or like this:
      //Json.obj(c._1 -> c._2)
    }
  }
然后您可以使用
Json.toJson(list.toMap)
。否则,必须为
(String,String)
定义
写入的
,如下所示:

yourListName : {
  "1" : "2",
  "3" : "4"
}
implicit val writer = new Writes[(String, String)] {
    def writes(c: (String, String)): JsValue = {
      Json.obj("something" -> c._1 + ", " + c._2)
      //or like this:
      //Json.obj(c._1 -> c._2)
    }
  }

请确保将此编写器放在本文讨论的范围内,json 2.1还不支持元组,主要是因为json不支持元组。如果要将元组作为数组写入,可以对元组使用隐式格式:

implicit def tuple2Writes[A, B](implicit aWrites: Writes[A], bWrites: Writes[B]): Writes[Tuple2[A, B]] = new Writes[Tuple2[A, B]] {
  def writes(tuple: Tuple2[A, B]) = JsArray(Seq(aWrites.writes(tuple._1), bWrites.writes(tuple._2)))
}

您可以在一行中执行此操作,只需声明此隐式:

implicit def tuple2[A : Writes, B : Writes] = Writes[(A, B)] ( t =>  Json.obj("something1" -> t._1, "something1" -> t._2) )

你能帮我解决这个问题吗?
没有为类型Map[String,Any]找到Json反序列化程序。尝试实现此类型的隐式写入或格式。
Map(语句2->Map(“计量单位”->)列表(Map(此->节流阀Cv等于15.6 gal/min psi½)、Map(此->15.6 gal/min psi½)、Map(此->120 gal/min psi½)、Map(此->120 bara.)、Map(节流阀Cv->节流阀Cv等于15.6 gal/min psi½)、Map(节流阀Cv->15.6 gal/min psi½),
用于该类数据