JSON Serialization

NETXPF provides a class called JSON to help with serialization of arbitrary data to JSON.
JSON.JSONify allows you to serialize any object by names and values of public properties, recursively.
It also allows you to independently serialize arrays, strings, and ValueTypes (like double or int).

Serialize (escape) a string

Console.WriteLine(JSON.JSONify("mystring \"with\" quotes"));
Output: mystring \"with\" quotes

Serialize an object (by public properties)

class MyObject {
public string A { get;set; }
public int B {get;set;}
Console.WriteLine(JSON.JSONify(new MyObject { A = "testing", B = 100 }));

Output: {A:"testing",B:100}

Serialize an array

int[] testArray = new int[] { 1, 2, 3 };

Output: [1,2,3]

Last edited Sep 16, 2011 at 3:57 PM by dacris, version 2


No comments yet.