I'm parsing a JSON string using MiniJson in Unity. Now I have a value that's a list of strings. Though I get this an object. The underlying type of the object is a List<object>, but actually it should be a List<string>. So currently I do this:
void SetInfo(Dictionary<string,object> info) {
Colors = (info["colors"] as List<object>).OfType<string>().ToList();
}
The dictionary is what I get from the MiniJson library. This works perfectly. Though seems a bit ugly, a lot of unnecessary casting, and I was wondering if there's a better way of doing this. Mostly I'm looking for cleaner code, and faster execution, since there are a lot of these entries.
Edit: I wasn't very clear about this. In the info dictionary there are a bunch of key/value pairs, the type of the values vary. I can cast most very easily, but the info["colors"] object is the one I'm having problems with.
So when I do info["colors"] I get an object, with an underlying type List<object>. The objects in this list are actually strings.
Also, there's not really a performance problem here, since it's only called once at the start of the program, though there is a noticeable lag currently, I'm going to put it on it's own thread anyway so no problem there. The faster execution is just out of curiosity.
Dictionary<string, List<string>>?info["colors"]. @Magnus, there are other values in it aswell. For instance the info["cmc"] is an int.