Jak zastąpić wartość w wartości JSON w grze?
kod zilustrować:
Jak zamienić wartość JSON w 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 =>
nie manipulować ciągi JSON. w dół tej drogi leży szaleństwo. konwertujesz ciąg json do natywnej struktury danych, manipulujesz strukturą, a następnie ponownie kodujesz do json. –
Podobnie jak MarcB lub użyj funkcji Json Coast2Coast http://mandubian.com/2012/10/29/unveiling-play-2-dot-1-json-api-part3-json-transformers/ –
Jeśli [moja odpowiedź] (http://stackoverflow.com/a/18069519/2643828) był dla ciebie pomocny, wybierz go jako zaakceptowaną odpowiedź. – Zeimyth