简体   繁体   English

使用Play for Scala,如何从POST请求中读取JSON正文{a =…,b =…,c…}?

[英]Using Play for Scala, how do I read in JSON body {a=…,b=…,c…} from POST request?

I have a JSON body arriving in a POST request. 我有一个JSON主体到达POST请求。 For simplicity sake, let's say it is: 为了简单起见,假设它是:

{"a":1,"b":2,"c":3,"d":4}

How do I read those values into variables a , b , c , d in a Play controller, and what should the appropriate line in the routes file look like? 如何在Play控制器中将这些值读入变量abcd ,以及routes文件中的相应行应该是什么样?

使用JsValue.as/asOpt

val a = (body \ "a").as[Long]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Scala&Play Framework中从request.body读取JSON值 - Read a JSON value from request.body in Scala & Play Framework 如何将JSon作为BODY发送到Android应用程序的服务器POST请求中? - How do I send JSon as BODY In a POST request to server from an Android application? HTTP 在 Scala 中使用 JSON 主体中的变量发布请求 - HTTP Post Request in Scala using variables in JSON body 如何从 ASP.NET 核心中的 JSON 请求正文中读取多个参数? - How do I read multiple parameters from a JSON request body in ASP.NET Core? 如何通过Bee Client(Scala)发出将JSON作为正文传递的POST请求? - How to make a POST request passing JSON as body with Bee Client (Scala)? 如何使用Dropwizard读取JSON请求体 - How to read JSON request body using Dropwizard 如何发送带有json正文的帖子请求,其中正文仅包含一个字符串而不是键值对? - How do I send post request with json body where the body only contains a string not a key value pair? 尝试使用 springboot 从 POST 请求正文读取嵌套 JSON 时获取空值 - Getting null when trying to read nested JSON from POST request body using springboot 如何使用 Actix-Web 从同一请求中提取路径参数并解析 JSON 正文 - How do I extract path parameters and parse JSON body from the same request using Actix-Web 如何使用 C# 在 POST 请求中发送 json 请求正文数据 - How to send json request body data in POST request using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM