gpt4 book ai didi

java - 如何使用 RestTemplate 解析没有键的 json 值?

转载 作者:行者123 更新时间:2023-12-02 09:41:36 25 4
gpt4 key购买 nike

我想解析 json 值,但有一些值没有键。

像这样

"geometry": {
"type": "LineString",
"coordinates": [
[
127.08373748622218,
37.529508099979225
],
[
127.08355138558433,
37.529735847943925
]
]
}

几何.类

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Geometry {
private String type;
private Coordinate coordinates;
}

坐标类

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Coordinate {
private List<Double[]> xy;
}

然后我看到了这个错误

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `kr.seoulmaas.ieye.service.dto.path.walk.Coordinate` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 133] (through reference chain: kr.seoulmaas.ieye.service.dto.path.WalkPathResDto["features"]->java.util.ArrayList[0]->kr.seoulmaas.ieye.service.dto.path.walk.Feature["geometry"]->kr.seoulmaas.ieye.service.dto.path.walk.Geometry["coordinates"])

最佳答案

private Coordinate coordinates;应该是private List<Coordinate> coordinates;因为它是 JSON 中的一个数组,但由于该数组仅包含数组,因此您需要一个列表列表:List<List<Double>> coordinates (由@JBNizet 建议)。

关于java - 如何使用 RestTemplate 解析没有键的 json 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57026305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com