gpt4 book ai didi

java - 读取 JSON 时出现 400 错误

转载 作者:行者123 更新时间:2023-12-01 16:50:28 25 4
gpt4 key购买 nike

我正在发送以下 JSON:

{
"sqId": "10009",
"pCode": [
{
"key": [
[
1,
0,
1
]
]
}
],
"hdId": "87",
"sType": [
{
"key": [
{
"id": "id_1",
"q": "1",
"pCode": "pCode_1",
"Type": "T_1",
"Level": "f"
}
]
}
]
}

它与以下 POJO 映射:

public class Pinfo {

protected String sqId;
protected String hdId;
protected Map<String, Integer> pCode;
protected Map<String, List<sType>> sType;

public Map<String, List<sType>> getsType() {
return sType;
}

public void setsType(Map<String, List<sType>> sType) {
this.sType = sType;
}

public String getsqId() {
return sqId;
}

public void setsqId(String sqId) {
this.sqId = sqId;
}

public Map<String, Integer> getpCode() {
return pCode;
}

public void setpCode(Map<String, Integer> pCode) {
this.pCode = pCode;
}

public String gethdId() {
return hdId;
}

public void sethdId(String hdId) {
this.hdId = hdId;
}

}

现在使用以下代码读取 JSON:

Map<String, Integer> pMap = (Map<String, Integer>) PinfoObj.getpCode(); //Getting Error 
logger.debug("### pMap ###"+pMap.values());

但我收到错误:

"Could not read document: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token\n at [Source: java.io.PushbackInputStream@5ed7c090; line: 2, column: 40] (through reference chain: com.ve.pg.dto.Pinfo[\"pCode\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token\n at [Source: java.io.PushbackInputStream@5ed7c090; line: 2, column: 40] (through reference chain: com.vonage.pg.dto.Pinfo[\"pCode\"])"

目前无法弄清楚我缺少什么,任何想法或提示都会很棒。

最佳答案

错误:

Could not read document: Can not deserialize instance of
java.util.LinkedHashMap out of START_ARRAY token

告诉您“我遇到了 START_ARRAY token ( [ ),但您要求我反序列化为 map ,因此我希望找到 START_OBJECT token ( { )”

你的错误是尝试反序列化类似的东西

[{
"key": [
[
1,
0,
1
]
]
}]

Map<String, Integer> ,而实际上是 List<Map<String, List<List<Integer>>>> 。您应该更改 JSON 的结构,或更改要反序列化的类型。

同样的错误应该被修复为 sType .

关于java - 读取 JSON 时出现 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120191/

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