使用C#在REST(WEB API)中定义了方法。
这里我试图使用wwwform将复杂数据作为字符串发布在Unity C#脚本中,但我无法发送/发布以下
string abc = "[{";
for (int i = 0; i < SessionNeedles.Count; i++)
{
abc += "\"PositionX\":\"" + SessionNeedles[i].PositionX + "\",";
abc += "\"PositionY\":\"" + SessionNeedles[i].PositionY + "\",";
abc += "\"PositionZ\":\"" + SessionNeedles[i].PositionZ + "\",";
abc += "\"RotationX\":\"" + SessionNeedles[i].RotationX + "\",";
abc += "\"RotationY\":\"" + SessionNeedles[i].RotationY + "\",";
abc += "\"RotationZ\":\"" + SessionNeedles[i].RotationZ + "\",";
abc += "\"RotationW\":\"" + SessionNeedles[i].RotationW + "\",";
abc += "\"ScaleX\":\"" + SessionNeedles[i].ScaleX + "\",";
abc += "\"ScaleY\":\"" + SessionNeedles[i].ScaleY + "\",";
abc += "\"ScaleZ\":\"" + SessionNeedles[i].ScaleZ + "\",";
abc += "\"Prefab\":\"" + SessionNeedles[i].Prefab + "\",";
abc += "\"NeedleName\":\"" + SessionNeedles[i].NeedleName + "\"";
abc += "},{";
}
abc = abc.Substring(0, abc.Length - 2) + "]";
WWWForm form = new WWWForm();
form.AddField("Duration", 5);
form.AddField("PatientId", "7");
form.AddField("SessionNeedles", abc);
WWW www = new WWW(_AddSessionUrl, form);
StartCoroutine("AddSession", www);
答案 0 :(得分:0)
我不确定你的意思是“无法发送”。 你在Unity结束时遇到错误吗?在服务器上?
请使用JSON序列化库(即。JSON.NET,SimpleJSON&lt; - 尚未尝试过,但我想分享一个免费选项),它将使您的代码更具可读性和可维护性;你可能会遇到语法错误。
您没有附加协同程序代码,但您必须yield return www;