Skip to content

AcresCoreJson.h#

Core/Source/AcresCoreJson.h Generated

A small JSON document reader for ACRES Core (no Unreal, no third-party library): the Core loads the same Content/Simulation files the game reads with Unreal's FJsonObject (site.json, surface_polygons.json, fields.json, tractor.json, farm.json, soils.json, sensors_polaris.json, ...). Numbers are doubles, objects keep their key order. Load-time only; not thread-safe while parsing, read-only (and thread-safe) afterwards.

ReadFileBytes#

Reads a whole binary file into Out; false when it cannot be read.

bool ReadFileBytes(const std::string& Path, std::vector<unsigned char>& Out);

FJson#

class FJson

One JSON value. Objects are ordered (key, value) lists; lookups are linear, which is fine for configuration files.

FJson::Parse#

Parses a document.

Argument Description
Text The JSON text.
Out Receives the root value.
Error Receives "what at offset N" on failure (may be null).

Returns: True on success.

static bool Parse(const std::string& Text, FJson& Out, std::string* Error = nullptr);

FJson::Load#

Reads and parses a file; false (with Error) when it cannot be read or parsed.

static bool Load(const std::string& Path, FJson& Out, std::string* Error = nullptr);

FJson::Kind#

Kind of this value.

EKind Kind() const ;

FJson::AsNumber#

The number (booleans as 0 / 1), or Default for any other kind.

double AsNumber(double Default = 0) const ;

FJson::AsBool#

The boolean (numbers: non-zero), or Default.

bool AsBool(bool Default = false) const ;

FJson::AsString#

The string, or an empty one.

const std::string& AsString() const ;

FJson::Items#

Array elements (empty for a non-array).

const std::vector<FJson>& Items() const ;

FJson::Members#

Object members in file order (empty for a non-object).

const std::vector<std::pair<std::string, FJson>>& Members() const ;

FJson::Size#

Number of array elements or object members.

size_t Size() const ;

FJson::operator[]#

Array element I (a shared null value when out of range).

const FJson& operator[](size_t I) const;

FJson::operator[]#

Object member Key (a shared null value when absent).

const FJson& operator[](const char* Key) const;

FJson::Has#

True when this object has member Key.

bool Has(const char* Key) const;

FJson::Number#

Member Key as a number, or Default when absent or not a number.

double Number(const char* Key, double Default = 0) const ;

FJson::Str#

Member Key as a string, or Default when absent or not a string.

std::string Str(const char* Key, const std::string& Default = ;) const;

EKind#

enum EKind : int

Value kinds.

Value Description
NullKind
BoolKind
NumberKind
StringKind
ArrayKind
ObjectKind