【发布时间】:2018-09-10 01:26:58
【问题描述】:
我正在尝试在 UWR 之上制作自己的 JSON Web 请求包装器,因此更容易从一个脚本调试和更改所有网络请求,而不是在每个场景中调试和更改
但我不知道如何从协程返回string,谁能帮帮我?
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
namespace Test
{
public class JSONUtils : MonoBehaviour
{
public string GetJSON(string uri)
{
// How to return a string from RequestJSON?
StartCoroutine(RequestJSON(uri));
}
private IEnumerator RequestJSON(string url)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
yield return www.downloadHandler.text;
}
}
}
}
}
【问题讨论】:
-
你可以使用这个其他的包装器 => github.com/proyecto26/RestClient
标签: c# web-services unity3d wrapper