gpt4 book ai didi

java - "Expected BEGIN_OBJECT but was STRING at line 1 column 1"

转载 作者:IT老高 更新时间:2023-10-28 11:30:06 29 4
gpt4 key购买 nike

我有这个方法:

public static Object parseStringToObject(String json) {
String Object = json;
Gson gson = new Gson();
Object objects = gson.fromJson(object, Object.class);
parseConfigFromObjectToString(object);
return objects;
}

我想用以下方式解析 JSON:

public static void addObject(String IP, Object addObject) {
try {
String json = sendPostRequest("http://" + IP + ":3000/config/add_Object", ConfigJSONParser.parseConfigFromObjectToString(addObject));
addObject = ConfigJSONParser.parseStringToObject(json);
} catch (Exception ex) {
ex.printStackTrace();
}
}

但我收到一条错误消息:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1

最佳答案

即使没有看到您的 JSON 字符串,您也可以从错误消息中看出,它不是被解析为您的类实例的正确结构。

Gson 期望您的 JSON 字符串以对象左大括号开头。例如

{

但是你传递给它的字符串以一个开引号开始

"

关于java - "Expected BEGIN_OBJECT but was STRING at line 1 column 1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28418662/

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