C# Class Jayrock.Json.FreeJsonMemberReadingHelper

Helps reading JSON members from an underlying JsonReader without regard to the order (free) in which they appear. Members are buffered or streamed as needed.
A JsonReader has a stream-oriented interface where the underlying JSON data is tokenized and yielded sequentially. When reading a JSON object, members must be processed in the order in which they are yielded by the underlying reader. If an application requires some members of a JSON object to correctly process the remaining members then those member may need to be read in advance to prepare for further processing. For example, suppose the JSON object { "type": "date", "format": "M/d/yyyy", "value": "5/5/2008" } represents a date encoded in the value member as a JSON string. Suppose further, the type confirms that the entire JSON object indeed describes a date and the format member specifies how to interpret the value member. To correctly create the date, an application would have to assert the type member, then read the format member to determine how to decode the value member value correctly. If the application assumes that the members are always provided in the natural order just described then it can simply use a JsonReader and process them in sequence along with their values. However, if the JSON object instead has members out of order, as in { "value": "5/5/2008", "type": "date", "format": "M/d/yyyy" }, then reading becomes a bit more cumbersome. The application would have to buffer the value and format member values until it has at least seen the type member and asserted its value to be date. Then it has to return to the buffered value of the format member and use it to finally decode the also-buffered value member. This is where FreeJsonMemberReadingHelper can help tremendously. The application can call its ReadMember method to read members in the natural order of processing (e.g., type, format and value) rather than how they have been actually ordered by some source. FreeJsonMemberReadingHelper will buffer or stream from the underlying JsonReader as needed. Once the required members have been processed, the GetTailReader method can be used to read auxillary or optional members in their order of appearance.
Datei anzeigen Open project: atifaziz/Jayrock Class Usage Examples

Private Properties

Property Type Description
TryPopBufferedMember JsonBuffer

Public Methods

Method Description
FreeJsonMemberReadingHelper ( Jayrock.Json.JsonReader reader ) : System
GetTailReader ( ) : Jayrock.Json.JsonReader

Gets a reader than can be used to read remaining members, which could include buffered and non-buffered members.

ReadMember ( string name ) : Jayrock.Json.JsonReader

Reads a member with a given (case-sensitive) name and returns a JsonReader that can be used to read the value. Otherwise it throws an exception.

The caller should not use the returned JsonReader instance for any other purpose but reading the value. It is possible that this method will return the same instance as BaseReader or a separate instance.

ToString ( ) : string

Returns the same string returned by the JsonReader.ToString implementation of BaseReader.

TryReadMember ( string name ) : Jayrock.Json.JsonReader

Attempts to locate a member with a given (case-sensitive) name and returns a JsonReader that can be used to read the value. Otherwise it returns null.

The caller should not use the returned JsonReader instance for any other purpose but reading the value. It is possible that this method will return the same instance as BaseReader or a separate instance.

Private Methods

Method Description
TryPopBufferedMember ( string name ) : JsonBuffer

Method Details

FreeJsonMemberReadingHelper() public method

public FreeJsonMemberReadingHelper ( Jayrock.Json.JsonReader reader ) : System
reader Jayrock.Json.JsonReader
return System

GetTailReader() public method

Gets a reader than can be used to read remaining members, which could include buffered and non-buffered members.
public GetTailReader ( ) : Jayrock.Json.JsonReader
return Jayrock.Json.JsonReader

ReadMember() public method

Reads a member with a given (case-sensitive) name and returns a JsonReader that can be used to read the value. Otherwise it throws an exception.
The caller should not use the returned JsonReader instance for any other purpose but reading the value. It is possible that this method will return the same instance as BaseReader or a separate instance.
/// A member with the requested name was not found. ///
public ReadMember ( string name ) : Jayrock.Json.JsonReader
name string
return Jayrock.Json.JsonReader

ToString() public method

Returns the same string returned by the JsonReader.ToString implementation of BaseReader.
public ToString ( ) : string
return string

TryReadMember() public method

Attempts to locate a member with a given (case-sensitive) name and returns a JsonReader that can be used to read the value. Otherwise it returns null.
The caller should not use the returned JsonReader instance for any other purpose but reading the value. It is possible that this method will return the same instance as BaseReader or a separate instance.
public TryReadMember ( string name ) : Jayrock.Json.JsonReader
name string
return Jayrock.Json.JsonReader