【问题标题】:how to parse a non-static nested member to Json?如何将非静态嵌套成员解析为 Json?
【发布时间】:2016-05-17 15:49:31
【问题描述】:

我有一个这样的JSON

{
    path: {
        : false
        costs: {
            DistanceChecker: 3
        } penalties: {

        }
    },
{
    path: {
        useHovLane: false,
        costs: {
            DistanceChecker: 1,
PenaltyCostChecker: 2
            } penalties: {
                MoreSegmentsPenalty: 2
            }

    }
}

您可以看到costspenalties 的嵌套成员数量并不总是相同。

如何将它们解析为 JSON?

这是我的代码,但它失败了,因为 costs 无法自动解析为字符串。

如果可能的话,你会建议我怎么做?

@Override
public CompleteRoutingResponse parseToDto(String entity) throws IOException {
    CompleteRoutingResponse routingResponse = mapper.readValue(entity, CompleteRoutingResponse.class);
}

【问题讨论】:

  • 嗯,看起来不像一个有效的 json

标签: java json parsing jackson


【解决方案1】:

一般来说,为了能够通过 JSON 解析这个输入字符串,这需要它的结构按照 JSON 正确。您是否介意检查上游系统以向您发送格式正确的 JSON 数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多