- Home /
'System.ArgumentException' when deserializing class using JsonFx
I want to deserialize some data from JSON that is of type Dictionary. What I want is for each key it encounters the parser will instantiate a StateInfo object for me.
using System;
using System.Collections.Generic;
using System.IO;
using JsonFx;
namespace JSONTest
{
public class SkillState
{
int level;
int xp;
}
public class MyData
{
public Dictionary<string, SkillState> skills;
}
class Program
{
static void Main(string[] args)
{
/*
{
"skills":
{
"attack":
{
"level": 0,
"xp": 200
}
}
}
*/
string input = "{\"skills\": {\"attack\": {\"level\": 0,\"xp\": 200} } }";
JsonReader reader = new JsonReader(input);
MyData data = reader.Deserialize(typeof(MyData)) as MyData;
}
}
}
When I run this I get this exception on Line 593 of JsonReader.cs:
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: The value "System.Collections.Generic.Dictionary`2[System.String,System.Object]" is not of type "JSONTest.SkillState" and cannot be used in this generic collection.
Thanks for any help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613133946im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
JsonFX and Polymorphism? 1 Answer
Deserializing Json String 1 Answer
Why is scene object serialized multiple times when entering play mode? 1 Answer
Save data through xml Serialization on iOS 1 Answer
Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers