Sample code for 30+ languages & platforms
C#

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat C# Downloads

C#
//  Create JSON with members of different data types.
Chilkat.JsonObject json = new Chilkat.JsonObject();

json.UpdateInt("a",123);
json.UpdateBool("b",true);
json.UpdateNull("c");

json.EmitCompact = false;
Debug.WriteLine(json.Emit());

//  Resulting JSON:
//  {
//    "a": 123,
//    "b": true,
//    "c": null
//  }

string a = json.StringOf("a");
Debug.WriteLine(a);

string b = json.StringOf("b");
Debug.WriteLine(b);

string c = json.StringOf("c");
Debug.WriteLine(c);

//  Output

//  123
//  true
//  null

//  If you want to get the integer, boolean, or null value
//  you need to use the methods matching the data type
int ival = json.IntOf("a");
bool bval = json.BoolOf("b");
bool hasNull = json.IsNullOf("c");