Search code examples
c#jsonlitjson

LitJSON Library for format FLOAT / DOUBLE issue


since JSON ist a format that can be written as string it has to be interpreted by an library or sometimes native by the language itself.

In the older versions of C# there is nothing like that. Using the library LitJSON I have the following problem I have a class called Vector3 containing 3 float values (not double).

public class Vector3 {
 public float x{get;set;}
 public float y{get;set;}
 public float z{get;set;}
}

Using the following snipped of code with LitJSON it shoudl actually fill an instance of Vector3 with values.

Vector3 test = JsonMapper.ToObject<Vector3>("{'x':1.0,'y':1.0,'z':1.0}");

But an error occures 'Can't assign value (type Single.Double) to System.Single'

It seems it only knows double but no float :/

Any solution for this?


Solution

  • I wanted to comment but my reputations are < 50.

    I was using LitJson in Unity3D (scripting language Mono C#). I faced the same problem while parsing the json to an object which have lot of float mebmbers. I have added float support to LitJson library. Let me know if you still require this.