Kyle Luke Kyle Luke - 1 year ago 99
JSON Question

Parsing JSON Array with DynamicForm Play framework 2.2.6

I have JSON array of Objects that comes from user page

{[1].id=10, [0].name=banana, [1].measurementSystem=g, [1].name=bacon, [0].id=2, [0].cal=23, [1].cal=23, [0].measurementSystem=g}

How can I get all IDs from this object array into a integer Java array?
I tried this:

DynamicForm data = Form.form().bindFromRequest();
for (String s :{

But it returns the array of all values.

So how can I get those ids only?

Answer Source

If the DynamicForm isn't working, I'd suggest trying to just parse the JSON as JSON. You can get a JsonNode object from the request using this code:

JsonNode json = request().body().asJson();

Using this you can then process the JSON to pull out whatever data you need.

Working with JSON in Play! should be documented here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download