- Home /
Question by
juliancruz · Oct 08, 2014 at 04:53 AM ·
wwwjson
Parse json/application with unity.
Hi, I need to know how could I parse this data from unity?
http://www.transportemos.com/SvtLoginMobile?dispId=123456
private IEnumerator RequestOnlineServiceInternal(string url, WWWForm form)
{
WWW service;
if (form == null)
service = new WWW(url);
else
service = new WWW(url, form);
while ( !service.isDone )
yield return null;
yield return service;
Hashtable data = JSON.JsonDecode(service.text) as Hashtable;
Debug.Log (data);
}
I tried to using this, but the log is empty. How can I parse that json, because the service.text is empty too, but if you open the url, you could see the information isn't empty. There are data, but unity doesn't parse
Comment
Answer by Landern · Oct 08, 2014 at 05:06 AM
Was the paring unsuccessful? There should be an overload for the static methods JsonDecode that takes a ref bool. See what happens when you change your code a bit to log the success:
private IEnumerator RequestOnlineServiceInternal(string url, WWWForm form)
{
bool result = false;
WWW service;
if (form == null)
service = new WWW(url);
else
service = new WWW(url, form);
while ( !service.isDone )
yield return null;
yield return service;
Hashtable data = JSON.JsonDecode(service.text, ref result) as Hashtable;
Debug.Log (string.Format("Json Decode successful? {0}", result.ToString()));
Debug.Log (data);
}
Your answer
Follow this Question
Related Questions
Upload/store string to html/json script?? 0 Answers
Integrating Watson Speech-to-Text with Unity 1 Answer
iPhone bad URL 0 Answers