- Home /
Cannot cast from source type to destination type Json
I'm retrieving a json file from my server and then using Json to deserialize the content. How ever I keep receiving this error " Cannot cast from source type to destination type", I was following the steps of the Minijson script but yet this error still comes up. Some help would be appreciated.
using System.Collections.Generic;
using MiniJSON;
using UnityEngine;
using System.Collections;
public class MoreGames : MonoBehaviour {
public WWW image1Request;
public WWW url1Request;
public string mgImage1;
Dictionary<string, object>[] dictArray;
public List<string> jsonList;
void Start () {
//creating url
image1Request = new WWW("http://development.someurl.com/MoreGames/MoreGames.json");
StartCoroutine(ImageOne(image1Request));
}
IEnumerator ImageOne(WWW www)
{
//wait until url is loaded
yield return www;
//load image into texture slot
if (www.error == null)
{
//assigning URLS
var dict = Json.Deserialize(www.text) as Dictionary<string,object>;
Debug.Log(www.text);
Debug.Log("deserialized: " + dict.GetType());
Debug.Log("dict['string']: " + (string)dict["widget"]);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
}
Comment