IBM Watson会话服务错误:无法从“方法组”转换为“conversation.onMessage”

我试图统一运行IBM Watson 会话服务 ,然后在这里,代码片段

private Conversation m_Conversation = new Conversation(); private string m_WrokspaceID = "xyz"; private string m_input = "help"; // Use this for initialization void Start () { Debug.Log("user : " + m_input); m_Conversation.Message(OnMessage, m_WrokspaceID, m_input); } void OnMessage(MessageResponse resp, string customData) { foreach (Intent mi in resp.intents) { Debug.Log("intent : " + mi.intent + ", confidence :" + mi.confidence); } Debug.Log("response :" + resp.output.text); } 

但我得到这个错误

 cannot convert from 'method group' to 'conversation.onMessage' 

我做错了什么? 我从watson官方github repo获得的代码片段。

返回的对象作为答案建议: 在此处输入图像描述

您可以将响应转换为字典并尝试从那里获取值。 使用通用对象而不是静态数据模型,您可以通过响应传递更多内容。

 private void OnMessage(object resp, string customData) { Dictionary respDict = resp as Dictionary; object intents; respDict.TryGetValue("intents", out intents); foreach(var intentObj in (intents as List)) { Dictionary intentDict = intentObj as Dictionary; object intentString; intentDict.TryGetValue("intent", out intentString); object confidenceString; intentDict.TryGetValue("confidence", out confidenceString); Log.Debug("ExampleConversation", "intent: {0} | confidence {1}", intentString.ToString(), confidenceString.ToString()); } } 

根据Conversation源代码中的第32行 ,代表更改为:

 public delegate void OnMessage(object resp, string customData); 

您必须更改OnMessage方法以反映:

 void OnMessage(object resp, string customData) { // ... }