2015-07-20 18 views
0

我在团结和C#新的和我寻遍找dictionaryWithContentsOfURL(目标C)在Unity相当于(C#)。如何从URL的内容并把它在字典团结

或者请至少给我如何从给定的URL的内容,并把它放在字典或阵列,使得我可以将它实例化一个变量,并且在整个脚本中使用它的想法。非常感谢你。

+0

需要查看URL。每个URL都是不同的,并且抓取URL可能会也可能不容易。 – jdweng

+0

您可能需要一个属性列表/ xml解析器。的 – d4Rk

+0

可能重复的[替代HttpUtility.ParseQueryString而不的System.Web依赖?](http://stackoverflow.com/questions/27442985/alternative-to-httputility-parsequerystring-without-system-web-dependency) –

回答

0

为了从给定的URL获取的内容,你可以检查WWW class,这里是你的情况的简单例子。

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.processwww.isDone来查看进程/状态,请查看官方文档以获取更多详细信息。

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

解析XML,你可以通过谷歌搜索,大多数的事情,说C#将在Unity3D工作,以及找到很多教程。这是一个好的:Loading data from a xml file

我不知道你的“财产清单”的格式,但我所看到的,在我的Mac上的.plist文件都是XML。解析两者并没有什么不同。

+0

感谢您的想法,它可能解决我的问题,一旦我阅读链接你发布了,如果有的话,我不会忘记为这个答案投票。 – LouieJe