Question

est-il possible d'ajouter un nouveau champ à JSOBJECT?

val jsonObj = Json.obj()
jsonObj.put("field" -> 100) <==== Somthing like this

J'ai beaucoup de méthodes qui ajoutent de nouveaux champs.Comment puis-je créer de manière dynamique JSOBJECT?

Était-ce utile?

La solution

Oui, vous pouvez ajouter un nouveau champ à l'aide de la méthode "+".Notez que l'objet est immuable, cela créera une nouvelle copie de la JSOBJECT avec le champ ajouté:

val obj = Json.obj()
// obj - {}
val newObj = obj + ("name" -> JsString("Kip"))
// newObj - {"name":"Kip"}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top