Scala/Play: parse JSON into Map instead of JsObject

前端 未结 5 1198
小蘑菇
小蘑菇 2020-12-24 14:04

On Play Framework\'s homepage they claim that \"JSON is a first class citizen\". I have yet to see the proof of that.

In my project I\'m dealing with some pretty co

5条回答
  •  渐次进展
    2020-12-24 14:32

    You can simply extract out the value of a Json and scala gives you the corresponding map. Example:

       var myJson = Json.obj(
              "customerId" -> "xyz",
              "addressId" -> "xyz",
              "firstName" -> "xyz",
              "lastName" -> "xyz",
              "address" -> "xyz"
          )
    

    Suppose you have the Json of above type. To convert it into map simply do:

    var mapFromJson = myJson.value
    

    This gives you a map of type : scala.collection.immutable.HashMap$HashTrieMap

提交回复
热议问题