【发布时间】:2023-03-18 12:15:01
【问题描述】:
我正在使用 Watson Conversation。在 ResponseUtils 的第 90 行(在 getObject 中)尝试执行 ServiceCall 时出现异常:
final T model = GsonSingleton.getGsonWithoutPrettyPrinting().fromJson(reader, type);
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 647 path $.output.text
我探索了响应,我看到了这个: 响应{protocol=http/1.1, code=200, message=OK, url=https://gateway.watsonplatform.net/conversation-experimental/api/v1/workspaces/200afa7d-c71f-472a-ab6e-5bf162f6e319/message?version=2016-05-19}
这是我的代码:
import com.ibm.watson.developer_cloud.conversation.v1_experimental.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.Message;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions.Builder;
import com.ibm.watson.developer_cloud.http.ServiceCall;
public class TestConversation {
public static void main(String[] args) throws Exception{
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_05_19);
service.setEndPoint("https://gateway.watsonplatform.net/conversation-experimental/api");
service.setUsernameAndPassword("xxxxxxxx", "xxxxxx");
Builder builder = new NewMessageOptions.Builder().workspaceId("xxxxxxxxxxxx");
NewMessageOptions newMessageOptions = builder.inputText("hi").build();
ServiceCall<Message> serviceCall = service.message(newMessageOptions);
Message answer = serviceCall.execute();
}
}
【问题讨论】:
标签: java ibm-watson