如何将play jsObject转换为JSONObject?
示例:
val samplePlayJson = Json.obj(
"name" -> "Watership Down",
"location" -> Json.obj("lat" -> 51.235685, "long" -> -1.309197),
"residents" -> Json.arr(
Json.obj(
"name" -> "Fiver",
"age" -> 4,
"role" -> JsNull
),
Json.obj(
"name" -> "Bigwig",
"age" -> 6,
"role" -> "Owsla"
)
)
)
当我厌倦了在samplePlayJson
以上传递给接受JSONObject的Java api时,遇到类型不匹配错误
type mismatch;
found : play.api.libs.json.JsObject
required: org.json.JSONObject
如何将上面的samplePlayJson转换为org.json.JSONObject
?
答案 0 :(得分:0)
您可以将play.api.libs.json.JsObject
转换为字符串,然后将org.json.JSONObject
制成字符串。我没有找到直接的方法。
new JSONObject(samplePlayJson.toString())