PlayのJSON値の値を置き換えるにはどうすればよいですか?例示する
コード:
PlayのJSON値を置き換える方法
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 =>
あなたはJSON形式の文字列を操作しないでください。その道は狂っている。 json文字列をネイティブのデータ構造に変換し、構造を操作してからjsonに再エンコードします。 –
MarcBのように、またはJson Coast2Coastの機能を使用するhttp://mandubian.com/2012/10/29/unveiling-play-2-dot-1-json-api-part3-json-transformers/ –
[私の答え]( http://stackoverflow.com/a/18069519/2643828)が役に立ちました。それを受け入れられる回答として選択してください。 – Zeimyth