Come sostituire un valore in un valore JSON in Play?
Codice per illustrare:
Come sostituire un valore JSON in Play
def newReport() = Action(parse.json) { request =>
var json = request.body
if((json \ "customerId").as[Int] == -1){
// replace customerId after some logic to find the new value
}
json.validate[Report](Reports.readsWithoutUser).map {
case _: Report =>
non manipolare le stringhe JSON. su quella strada giace la follia. si converte la stringa json in una struttura dati nativa, si manipola la struttura, quindi si ri-codifica in json. –
Come MarcB, o utilizzare Json Coast2Coast presenta http://mandubian.com/2012/10/29/unveiling-play-2-dot-1-json-api-part3-json-transformers/ –
Se [la mia risposta] (http://stackoverflow.com/a/18069519/2643828) è stato utile per te, selezionalo come risposta accettata. – Zeimyth