C# Class Microsoft.WindowsAzure.MobileServices.JsonExtensions

Helpful extensions that make it easier to manipulate JSON values.
Nulls propagate through calls so for example, given a JSON object like { 'typeInfo': { 'bar' : 2 } }, you could just write obj.Get("typeInfo").Get("bar").AsInteger() to get the value 2. Given a JSON object like { 'baz': 2 }, you could write obj.Get("typeInfo").Get("bar").AsInteger() to get the value null.
Show file Open project: xamarin/azure-mobile-services Class Usage Examples

Public Methods

Method Description
Append ( this array, JToken value ) : Newtonsoft.Json.Linq.JArray

Add an element to a JSON array.

AsArray ( this value ) : Newtonsoft.Json.Linq.JArray

Convert a JSON value into an array, returning null if it's unable.

AsBool ( this value ) : bool?

Convert a JSON value into a bool, returning null if it's unable.

AsInteger ( this value ) : int?

Convert a JSON value into an int, returning null if it's unable.

AsNumber ( this value ) : double?

Convert a JSON value into a double, returning null if it's unable.

AsObject ( this value ) : Newtonsoft.Json.Linq.JObject

Convert a JSON value into an object, returning null if it's unable.

AsString ( this value ) : string

Convert a JSON value into a string, returning null if it's unable.

Get ( this value, string name ) : JToken

Gets a named value from an object.

GetPropertyValues ( this value ) : JToken>>.IEnumerable

Enumerate the member name/value pairs of a JSON object.

IsNull ( this value ) : bool

Determine if the value represents null.

Null ( ) : JToken

Get a null JSON value (that when serialized will stay null rather than not being written out).

Set ( this obj, string name, JToken value ) : JContainer

Set a named value on an object and return that object so multiple calls can be chained.

Set ( this obj, string name, bool value ) : JContainer

Set a named value on an object and return that object so multiple calls can be chained.

Set ( this obj, string name, double value ) : JContainer

Set a named value on an object and return that object so multiple calls can be chained.

Set ( this obj, string name, int value ) : JContainer

Set a named value on an object and return that object so multiple calls can be chained.

Set ( this obj, string name, string value ) : JContainer

Set a named value on an object and return that object so multiple calls can be chained.

TryConvert ( this value, object &propertyValue ) : bool

Try to convert a value to a CLR object.

TrySet ( this obj, string name, object value ) : bool

Set a named value on an object of any type. Unlike the other set overloads, this will attempt to convert arbitrary CLR values into the correct JSON types.

Private Methods

Method Description
NumericCanRoundtrip ( object value, Type desiredType ) : bool

Ensure that a numeric value can safely roundtrip as a double.

Method Details

Append() public static method

Add an element to a JSON array.
public static Append ( this array, JToken value ) : Newtonsoft.Json.Linq.JArray
array this The array to add to.
value JToken The element to add.
return Newtonsoft.Json.Linq.JArray

AsArray() public static method

Convert a JSON value into an array, returning null if it's unable.
public static AsArray ( this value ) : Newtonsoft.Json.Linq.JArray
value this The value to convert.
return Newtonsoft.Json.Linq.JArray

AsBool() public static method

Convert a JSON value into a bool, returning null if it's unable.
public static AsBool ( this value ) : bool?
value this The value to convert.
return bool?

AsInteger() public static method

Convert a JSON value into an int, returning null if it's unable.
public static AsInteger ( this value ) : int?
value this The value to convert.
return int?

AsNumber() public static method

Convert a JSON value into a double, returning null if it's unable.
public static AsNumber ( this value ) : double?
value this The value to convert.
return double?

AsObject() public static method

Convert a JSON value into an object, returning null if it's unable.
public static AsObject ( this value ) : Newtonsoft.Json.Linq.JObject
value this The value to convert.
return Newtonsoft.Json.Linq.JObject

AsString() public static method

Convert a JSON value into a string, returning null if it's unable.
public static AsString ( this value ) : string
value this The value to convert.
return string

Get() public static method

Gets a named value from an object.
public static Get ( this value, string name ) : JToken
value this /// The object to check (though the type is IJsonValue so multiple /// calls to Get can be chained together). ///
name string The name of the value to lookup.
return JToken

GetPropertyValues() public static method

Enumerate the member name/value pairs of a JSON object.
public static GetPropertyValues ( this value ) : JToken>>.IEnumerable
value this A JSON object.
return JToken>>.IEnumerable

IsNull() public static method

Determine if the value represents null.
public static IsNull ( this value ) : bool
value this The value to check.
return bool

Null() public static method

Get a null JSON value (that when serialized will stay null rather than not being written out).
public static Null ( ) : JToken
return JToken

Set() public static method

Set a named value on an object and return that object so multiple calls can be chained.
public static Set ( this obj, string name, JToken value ) : JContainer
obj this The object to set the value on.
name string The name to set.
value JToken The value to set.
return JContainer

Set() public static method

Set a named value on an object and return that object so multiple calls can be chained.
public static Set ( this obj, string name, bool value ) : JContainer
obj this The object to set the value on.
name string The name to set.
value bool The value to set.
return JContainer

Set() public static method

Set a named value on an object and return that object so multiple calls can be chained.
public static Set ( this obj, string name, double value ) : JContainer
obj this The object to set the value on.
name string The name to set.
value double The value to set.
return JContainer

Set() public static method

Set a named value on an object and return that object so multiple calls can be chained.
public static Set ( this obj, string name, int value ) : JContainer
obj this The object to set the value on.
name string The name to set.
value int The value to set.
return JContainer

Set() public static method

Set a named value on an object and return that object so multiple calls can be chained.
public static Set ( this obj, string name, string value ) : JContainer
obj this The object to set the value on.
name string The name to set.
value string The value to set.
return JContainer

TryConvert() public static method

Try to convert a value to a CLR object.
public static TryConvert ( this value, object &propertyValue ) : bool
value this The value to convert.
propertyValue object The converted value.
return bool

TrySet() public static method

Set a named value on an object of any type. Unlike the other set overloads, this will attempt to convert arbitrary CLR values into the correct JSON types.
public static TrySet ( this obj, string name, object value ) : bool
obj this The object to set the value on.
name string The name of the value to set.
value object The value to set.
return bool