私はHTTP応答を取得しようとします{"ReturnValue":""}
、 このコードはエラーを起こします。 spray.json.DeserializationException:によって引き起こさscala spray.json Jsonオブジェクトを取得する方法
JsArrayとして期待一覧が、{ "戻り値": ""}だ
によって引き起こさ
import spray.httpx.SprayJsonSupport._
import spray.json.DefaultJsonProtocol
import spray.http._
import spray.client.pipelining._
import scala.concurrent.duration._
import scala.concurrent.{ Await, Future }
import akka.actor.ActorSystem
import scala.concurrent.ExecutionContext.Implicits.global
class ApiHelper extends DefaultJsonProtocol {
case class Robot(name: String, color: Option[String], amountOfArms: Int)
implicit val RobotFormat = jsonFormat3(Robot)
def CallAPI(httpMethod: String, subURL: String): String = {
val apiLocation = "~~~"
val timeout = 5.seconds
implicit val system = ActorSystem("robotClient")
return httpMethod match {
case "GET" =>
val pipeline: HttpRequest => Future[List[Robot]] = sendReceive ~> unmarshal[List[Robot]]
val f: Future[List[Robot]] = pipeline(Get(s"$apiLocation"+subURL))
val robots = Await.result(f, timeout)
println(s"Got the list of robots: $robots")
return "hello"
}
}
}
:spray.json.DeserializationExceptionを:JsArrayとして期待されるリストですが、{"ReturnValue": "}}
spray.json.package $ .deserializationError(package.scala:23)at spray.json.CollectionFormats $$ ano N $ 1.read(CollectionFormats.scala:29) でspray.json.CollectionFormats $$アノン$ 1.read(CollectionFormats.scala:25) でspray.httpx.SprayJsonSupport $$ anonfun $ sprayJsonUnmarshaller $ 1.applyOrElse(SprayJsonSupport .scala:37) でspray.httpx.SprayJsonSupport $$ anonfun $ sprayJsonUnmarshaller $ 1.applyOrElse(SprayJsonSupport.scala:34) でscala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) スプレーで。 httpx.unmarshalling.Unmarshaller $$ anon $ 1 $$ anonfun $ unmarshal $ 1.apply(Unmarshaller.scala:29) at spray.httpx.unmarshalling.SimpleUnmarshaller.protect(SimpleUnmarshaller.scala:40) でspray.httpx.unmarshalling.Unmarshaller $$アノン$ 1.unmarshal(Unmarshaller.scala:29) でspray.httpx.unmarshalling.SimpleUnmarshaller.apply(SimpleUnmarshaller.scala:29) spray.httpx.unmarshallingで.SimpleUnmarshaller.apply(SimpleUnmarshaller.scala:23) で spray.httpx.unmarshalling.UnmarshallerLifting $$アノン$ 3.apply(UnmarshallerLifting.scala:35) で spray.httpx.unmarshalling.UnmarshallerLifting $$アノン$ 3.apply (UnmarshallerLifting.scala:34) spray.httpx.unmarshalling.UnmarshallerLifting $$アノン$ 2.apply(UnmarshallerLifting.scala:30)で でspray.httpx.unmarshalling.UnmarshallerLi fting $$アノン$ 2.apply(UnmarshallerLifting.scala:29) で spray.httpx.unmarshalling.package $ PimpedHttpResponse.as(package.scala:51) で spray.httpx.ResponseTransformation $$ anonfun $アンマーシャリング$ 1 apply(ResponseTransformation.scala:33) ... 13 more
Json Objectを取得する方法はありますか?