相关疑难解决方法(0)

Unity3D将json发布到ASP.NET MVC 4 Web Api

我如何使用json值发布ASP.NET MVC 4 Web Api控制器?我尝试了几种方法,但我不能使它有效.

首先,我的简化控制器动作:

[HttpPost]
public Interaction Post(Interaction filter)
{
     return filter;
}
Run Code Online (Sandbox Code Playgroud)

和Unity3D WWW的post方法:

public string GetJson(string url, WWWForm form)
{
    var www = new WWW(url, form);

    while (!www.isDone) { };

    return www.text;
}
Run Code Online (Sandbox Code Playgroud)

我的WWWForm在哪里:

var form = new WWWForm();
form.AddField("filter", interaction);
Run Code Online (Sandbox Code Playgroud)

我尝试指定标题,如:

public string GetJson(string url, byte[] data)
{
    var header = new Hashtable();
    header.Add("Content-Type", "text/json");

    var www = new WWW(url, data, header);

    while (!www.isDone) { };

    return www.text;
}
Run Code Online (Sandbox Code Playgroud)

我真的试图通过十多种不同的方式解决这个问题,我总是得到相同的结果:

Debug.Log(input); // {"Id":15,"Name":"Teste","Description":"Teste","Value":0.0,"Time":10.0}
Debug.Log(output); // …
Run Code Online (Sandbox Code Playgroud)

post json unity-game-engine asp.net-web-api

2
推荐指数
1
解决办法
6390
查看次数

标签 统计

asp.net-web-api ×1

json ×1

post ×1

unity-game-engine ×1