Class RendezvousJson

Namespace
Unity.Multiplayer.Core

The small JSON reader and writer the rendezvous client needs. Core has no JSON library (it is engine-free and netstandard2.1, and Unity ships no System.Text.Json), and every rendezvous body is one flat object of strings, numbers, booleans and nulls, so this handles exactly that.

public static class RendezvousJson
Inheritance
RendezvousJson
Inherited Members

Methods

GetInteger(IReadOnlyDictionary<string, object>, string)

The whole-number field name, or null when it is missing or not a whole number.

public static long? GetInteger(IReadOnlyDictionary<string, object> fields, string name)

Parameters

fields IReadOnlyDictionary<string, object>
name string

Returns

long?

GetString(IReadOnlyDictionary<string, object>, string)

The string field name, or null when it is missing or not a string.

public static string GetString(IReadOnlyDictionary<string, object> fields, string name)

Parameters

fields IReadOnlyDictionary<string, object>
name string

Returns

string

TryParseObject(string, out Dictionary<string, object>)

Reads one flat object into a dictionary (keys are case-sensitive). Strings come back as string, whole numbers as long, other numbers as double, booleans as bool and null as null. A nested object or array is skipped and read as null.

public static bool TryParseObject(string text, out Dictionary<string, object> fields)

Parameters

text string
fields Dictionary<string, object>

Returns

bool

False when text is not a JSON object.

Write(IEnumerable<KeyValuePair<string, object>>)

Writes one flat object. Values may be null, string, bool or any integer type; a null value writes null.

public static string Write(IEnumerable<KeyValuePair<string, object>> fields)

Parameters

fields IEnumerable<KeyValuePair<string, object>>

Returns

string

Exceptions

ArgumentNullException

fields is null.

ArgumentException

A value has a type this writer does not handle.