Currently I'm receiving the following JSON data in my action:
[
{ "civilStatus": "M" },
"and",
{ "familySize": "2|bw|4" },
"or",
{ "civilStatus": "D" }
]
I've been trying to use play.libs.Json
to parse the string I receive at the server, but I can't find a way to obtain the array nor the objects.
I have also looked at the org.codehaus.jackson.JsonNode
documentation, but I didn't figure any way. Also I'm using Java, not Scala.
I have found using Gson is easier. Just add it as a dependency in Build.scala file:
val appDependencies = Seq(
... other dpenedencies ...
"com.google.code.gson" % "gson" % "2.1",
... other dpenedencies ...
)
Then just parse with something like:
Gson gson = new Gson();
List<YourCustomBean> data = gson.fromJson(jsonString, new TypeToken<List<YourCustomBean>>(){}.getType());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.