下面是我的代码 我想解析出ai返回的话在(unity中)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using System.Text;
[Serializable]
public class MyJsonClass
{
public string access_token;
}
[Serializable]
public class MyAIJsonClass
{
public int scene_id;
public string query;
public string session_id;
}
public class BaiDuAI : MonoBehaviour
{
public Text p;
public InputField ip;
// 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存
// 返回token示例
public static string TOKEN = "24.adda70c11b9786206253ddb70affdc46.2592000.1493524354.282335-1234567";
// 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务
private static string clientId = "kxkKvExXYkczGy55KqrugfGj";
// 百度云中开通对应服务应用的 Secret Key
private static string clientSecret = "ueRkTIqCpOufpuIyo6QWrky8hyjSwH7r";
public void GetAccessToken()
{
StartCoroutine(getAccessToken());
}
public IEnumerator getAccessToken() {
string authHost = "https://aip.baidubce.com/oauth/2.0/token";
WWWForm f = new WWWForm ();
f.AddField ("grant_type", "client_credentials");
f.AddField ("client_id", clientId);
f.AddField ("client_secret", clientSecret);
WWW w = new WWW (authHost,f);
yield return w;
MyJsonClass v1 = JsonUtility.FromJson (w.text) as MyJsonClass;
TOKEN = v1.access_token;
Debug.Log (TOKEN);
p.text = TOKEN;
}
public void GetAIText()
{
StartCoroutine(getAIText());
}
public IEnumerator getAIText() {
string AiHost = "https://aip.baidubce.com/rpc/2.0/solution/v1/unit_utterance?access_token=" + TOKEN;
//WWWForm f = new WWWForm ();
//f.AddField ("scene_id",9596 );
//f.AddField ("query", ip.text);
//f.AddField ("session_id", "");
MyAIJsonClass vvp = new MyAIJsonClass ();
vvp.scene_id = 9596;
vvp.query = ip.text;
vvp.session_id = "";
byte[] postBytes =Encoding.UTF8.GetBytes(JsonUtility.ToJson(vvp));
Dictionary header = new Dictionary();
header["Content-Type"] = "application/json;charset=UTF-8";
WWW w = new WWW (AiHost,postBytes,header);
yield return w;
//if (w.error == null)
{
Debug.Log ( w.text);
p.text = w.text;
}
}
请求是空的。看error_msg
你好,我复制你的代码运行后报错,
{"log_id":151986976026499,"error_code":282900,"error_msg":"query is empty"}
UnityEngine.Debug:Log(Object)
c__Iterator1:MoveNext() (at Assets/Scripts/BaiDuAI.cs:78)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
方便发项目给我看看吗
unity的脚本是用c#写的
就你嘴甜~
其实UNIT的接入已经算很简单很简单了.文档清晰.版主尽责
这个不是c#嘛 hhh~ 处理逻辑到应用层看来还是很多不会吗
哈哈哈
太尽职了...哈哈哈.
半夜巡逻 最为致命!
已经解决就好
是的是的...
不一样,那个是unity。多了个y
和UNIT的名字一样...=.=
噢 ,UNIT,
还有,这平台叫UNIT,不叫UNTI
???json结果自己解析啊。你都拿到回复了还做不来么
这个回复,可以使用嘛?!
那你不是已经拿到回复了么
w是百度ai的回复
你w什么内容