0

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.

Somatik
  • 4,723
  • 3
  • 37
  • 49
Hugo Alves
  • 1,555
  • 2
  • 18
  • 41
  • 2
    Check this question for handling array of objects: http://stackoverflow.com/questions/6349421 – biesior Jun 04 '12 at 15:31

1 Answers1

0

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());
Ben
  • 1,537
  • 1
  • 10
  • 6