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
fieldsIReadOnlyDictionary<string, object>namestring
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
fieldsIReadOnlyDictionary<string, object>namestring
Returns
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
textstringfieldsDictionary<string, object>
Returns
- bool
False when
textis 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
fieldsIEnumerable<KeyValuePair<string, object>>
Returns
Exceptions
- ArgumentNullException
fieldsis null.- ArgumentException
A value has a type this writer does not handle.