Converting JSON string to a JSON object in Scala

后端 未结 4 921
生来不讨喜
生来不讨喜 2020-12-31 04:07

I want to convert a simple JSON string such as {\"Name\":\"abc\", \"age\":10} to the corresponding JSON object (not a custom Scala object such as \"Person\"). D

4条回答
  •  余生分开走
    2020-12-31 04:27

    The parseFull returns in-terms of Some(Map), parseRaw returns in terms of Some(JSONObject)

    import scala.util.parsing.json._
    
    val parsed = JSON.parseRaw("""{"Name":"abc", "age":10}""").getOrElse(yourDefault)
    

    parsed is the JSONObject

提交回复
热议问题