Skip to content

Instantly share code, notes, and snippets.

@prime31
Last active December 12, 2015 08:08
Show Gist options
  • Save prime31/4741428 to your computer and use it in GitHub Desktop.
Save prime31/4741428 to your computer and use it in GitHub Desktop.
// setup a semi-complex test object
var someObject = new SomeObject();
someObject.anotherObject = new AnotherObject();
someObject.anotherObjectList = new List<AnotherObject>
{
new AnotherObject(), new AnotherObject(), new AnotherObject(), new AnotherObject()
};
// serialize the class to json
var json = Json.jsonEncode( someObject );
Debug.Log( json );
// Test classes
public class SomeObject
{
// fields
public string someString;
public int someInt;
public float someFloat;
public AnotherObject anotherObject;
public List<AnotherObject> anotherObjectList;
// props
public string stringProp { get; set; }
public int intProp { get; set; }
public float floatProp { get; set; }
protected string protectedStringPrivateGetProp { private get; set; }
private string privateStringProp { get; set; }
public SomeObject()
{
var rand = new Random();
someString = Utils.randomString( 10 );
someInt = rand.Next();
someFloat = rand.Next();
stringProp = Utils.randomString( 15 );
intProp = rand.Next();
floatProp = rand.Next();
privateStringProp = Utils.randomString( 5 );
protectedStringPrivateGetProp = Utils.randomString( 15 );
}
}
public class AnotherObject
{
public float turd;
public string poopString;
public AnotherObject()
{
turd = 3423.234f;
poopString = Utils.randomString( 10 );
}
}
@maxme
Copy link

maxme commented Feb 8, 2013

What is this "Json" library ? https://gist.github.com/darktable/1411710 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment