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.
Afficher le fichier Open project: xamarin/azure-mobile-services Class Usage Examples

Méthodes publiques

Méthode 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

Méthode Description
NumericCanRoundtrip ( object value, Type desiredType ) : bool

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

Method Details

Append() public static méthode

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.
Résultat Newtonsoft.Json.Linq.JArray

AsArray() public static méthode

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.
Résultat Newtonsoft.Json.Linq.JArray

AsBool() public static méthode

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.
Résultat bool?

AsInteger() public static méthode

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.
Résultat int?

AsNumber() public static méthode

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.
Résultat double?

AsObject() public static méthode

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.
Résultat Newtonsoft.Json.Linq.JObject

AsString() public static méthode

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.
Résultat string

Get() public static méthode

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.
Résultat JToken

GetPropertyValues() public static méthode

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

IsNull() public static méthode

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

Null() public static méthode

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

Set() public static méthode

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.
Résultat JContainer

Set() public static méthode

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.
Résultat JContainer

Set() public static méthode

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.
Résultat JContainer

Set() public static méthode

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.
Résultat JContainer

Set() public static méthode

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.
Résultat JContainer

TryConvert() public static méthode

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.
Résultat bool

TrySet() public static méthode

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.
Résultat bool