Jürgen K.
Jürgen K.

Reputation: 3487

Parse list of list to a JSON object

I have the following data, which is a list of lists:

"segmentation": [[239.97,260.24,222.04,270.49,199.84,253.41,213.5,227.79,259.62,200.46,274.13,202.17,277.55,210.71,249.37,253.41,237.41,264.51,242.54,261.95,228.87,271.34]]

What I need to do is to parse the information to a JSON object without removing the second braces. I tried it with Jackson, but this fails with any data types.

Do you have any idea how to handle this?

Upvotes: 1

Views: 44

Answers (1)

GolamMazid Sajib
GolamMazid Sajib

Reputation: 9437

Parse to JsonNode will work. I think u try with invalid json. check:

String value = "{\n" +
                "  \"segmentation\": [\n" +
                "    [\n" +
                "      239.97,\n" +
                "      260.24,\n" +
                "      222.04,\n" +
                "      270.49,\n" +
                "      199.84,\n" +
                "      253.41,\n" +
                "      213.5,\n" +
                "      227.79,\n" +
                "      259.62,\n" +
                "      200.46,\n" +
                "      274.13,\n" +
                "      202.17,\n" +
                "      277.55,\n" +
                "      210.71,\n" +
                "      249.37,\n" +
                "      253.41,\n" +
                "      237.41,\n" +
                "      264.51,\n" +
                "      242.54,\n" +
                "      261.95,\n" +
                "      228.87,\n" +
                "      271.34\n" +
                "    ]\n" +
                "  ]\n" +
                "}";
        JsonNode jsonNode = new ObjectMapper().readTree(value);

Upvotes: 1

Related Questions