Skip to content

Repository files navigation

Here I store my improvements for SimpleJSON lib. [Original repository]

Original lib tweaks:

You can check if key contains in JSONClass

publicoverrideboolContainsKey(stringkey)

You can get list of JSONNode children

publicList<JSONNode>GetChildrenList()

My extensions:

In file SimpleJSONExtensions.cs

GetValueByType

publicstaticobjectGetValueByType(thisJSONNodeparam,TypeNeedType)

This method is suitable for reflection routines. It automatically selects suitable property to get the value of JSONNode.

FieldInfo[]fields=thisType.GetFields();objectvalue=myNode.GetValueByType(fields[0].FieldType);fields[0].SetValue(InstanceOfType,value);

ParseData

publicstaticvoidParseData(JSONClassparam,objectinstance)

You can deserialize JSONClass instance to object. First of all you need to add ParsableValue attribute to fields you want to deserialize. This fields must be named same as fields in JSON you want to deserialize. If you want to use a different name you can specify it in attributes constructor

publicclassEnergyModel{[ParsableValue]//Searching for MaxEnergy in JSONpublicfloatMaxEnergy;[ParsableValue("RSpeed")]//Searching for RSpeed in JSONpublicfloatEnergyRecreationSpeed;}

To deserialize just call the method. ParseData currently not supports arrays and nested object.

EnergyModelmodel=newEnergyModel();SimpleJSONExtensions.ParseData(json,model);

About

My improvements for SimpleJSON

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages