如何从URL获取内容并将其整合到字典中

时间:2015-07-20 12:32:54

标签: c# unity3d

我是Unity和C#的新手,我在整个搜索过程中找到了Unity(C#)中的dictionaryWithContentsOfURL(Objective C)。

或者请至少让我知道如何从给定的URL检索内容,并将其放在字典或数组中,以便我可以将其实例化为变量并在整个脚本中使用它。非常感谢你。

1 个答案:

答案 0 :(得分:0)

要从给定的网址中提取内容,您可以查看WWW class,这是一个简单的例子。

/auth

您可以致电IEnumerator ProcessContentFromInternet(string url) { WWW www = new WWW(url); yield return www; // waiting the request to finish if (www.error == null) { // if not error string response = www.text; // here is raw data // call another method for parsing the response text // will discuss it later ParseContentFromText(response); } else { Debug.LogError(www.error); // there is an error when access the url // need do something here } } 启动它,可能需要一段时间才能使用您的互联网和内容的大小。您可以使用StartCoroutine(ParseContentFrom(url));www.process查看流程/状态,查看官方文档了解更多详情。

我无法提供解析原始内容到字典/数组的详细解决方案,因为我不知道你将使用什么格式(我个人会推荐JSON,因为它可能是最容易处理的,请检查:{ {3}})。

对于解析XML,您可以通过Google搜索找到大量教程,大多数情况下说C#也可以在Unity3D中运行。这是一个很好的:SimpleJSON for Unity

我不确定你的“属性列表”的格式,但是对于我所看到的,我Mac上的.plist文件都是XML。解析这两者并没有什么不同。

相关问题