解析嵌套列表为JSON对象。

huangapple go评论67阅读模式
英文:

Parse list of list to a JSON object

问题

我有以下数据,它是一个列表的列表:

    "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]]

我需要做的是将这些信息解析为一个 JSON 对象,而不移除第二层括号。
我尝试过使用 Jackson,但对于任何数据类型都失败了。

你有任何处理这个的想法吗?
英文:

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?

答案1

得分: 1

以下是翻译好的内容:

解析为 `JsonNode` 将起作用我认为您尝试了无效的 JSON请检查

    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);
英文:

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);

huangapple
  • 本文由 发表于 2020年4月7日 15:39:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61075009.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定