Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

JSON library for Delphi

License

NotificationsYou must be signed in to change notification settings

tmcdos/tiny-json

Repository files navigation

This is a small and clean library for associative arrays with Boolean / Integer / Float / WideString values.Allows import (export) from (to) JSON text. Extensive error-checking.

Some open-source projects I would like to give credit:

The library was built for the ease of use and clean understandable code - performance was not a first priority so I have not made any benchmarking.

Features

  • Numeric and WideString indexes (similar to PHP arrays)
  • Boolean / Int64 / Double / WideString item values
  • Strict parsing of JSON with descriptive Exception on error
  • Simple interface (Add, Delete, Remove, Clear)
  • Simple iterators (First, Last, Prev, Next)

Types of node values

NameDescription
jsNullTheNULL value
jsBoolNode value isBoolean
jsIntNode value isInteger
jsFloatNode value isFloating-point
jsStringNode value isString
jsArrayNode is an array - has children

Iterators

  • TJSONEnum = procedure (Nomer: Integer; Elem: TJSONbase; Data: Pointer; Var Stop: Boolean);
  • TJSONEnumObj = procedure (Nomer: Integer; Elem: TJSONbase; Data: Pointer; Var Stop: Boolean) Of Object;

Parsing

function ParseJSON(JSON_str: PAnsiChar): TJSONbase;

Properties

NameTypeDescription
AssocBooleanWhether all keys are Numeric or at leastone key is String
ParentTJSONbaseWhere the given node belongs to
FirstChildTJSONbaseChilds are organized as a double-linked list
LastChildTJSONbaseChilds are organized as a double-linked list
NextTJSONbaseNext sibling (by the order of creation)
PrevTJSONbasePrevious sibling (by the order of creation)
SelfTypeTJSONtypeType of data in the current node
ValueVariantValue of the current node
CountIntegerNumber of children if the node is non-scalar
NameWideStringThe Stringkey of the current node if this is an associative array
IDIntegerThe Numerickey of the current node if this is non-associative array
Child[Index: Integer]TJSONbaseUsed to access the children of non-associative arrays
Field[Key: WideString]TJSONbaseUsed to access the children of associatve arrays
JsonTextAnsiStringStringification of the current node as JSON text

Methods

NameParametersReturnsDescription
ClearRemove all children
DeleteIdx: IntegerDelete a child from non-associative array and free the object
DeleteKey: WideStringDelete a child from associative array and free the object
RemoveIdx: IntegerTJSONbaseRemovee a child from non-associative array and return the object
RemoveKey: WideStringTJSONbaseRemove a child from associative array and return the object
ForEachIterator: TJSONEnum
UserData: Pointer
Iterates over the children of non-associative array
ForEachIterator: TJSONEnumObj
UserData: Pointer
Iterates over the children of associative array
AddB: BooleanTJSONbaseAppends a newBoolean child to the node (making it an array if not already, returns the new child)
AddI: Int64TJSONbaseAppends a newInteger child to the node (making it an array if not already, returns the new child)
AddD: DoubleTJSONbaseAppends a newFloating-point child to the node (making it an array if not already, returns the new child)
AddS: WideStringTJSONbaseAppends a newString child to the node (making it an array if not already, returns the new child)
AddA: TJSONbaseAppends an existing array as a child to the node (making it an array if not already
AddKey: WideString
B: Boolean
TJSONbaseAppends a newBoolean child to the node (making it an array if not already, returns the new child)
AddKey: WideString
I: Int64
TJSONbaseAppends a newInteger child to the node (making it an array if not already, returns the new child)
AddKey: WideString
D: Double
TJSONbaseAppends a newFloating-point child to the node (making it an array if not already, returns the new child)
AddKey: WideString
S: WideString
TJSONbaseAppends a newString child to the node (making it an array if not already, returns the new child)
AddKey: WideString
A: TJSONbase
Appends an existing array as a child to the node (making it an array if not already

Possible errors

  • Unsupported assignment of object
  • Automatic indexing overflow
  • Invalid data type assigned to TJSONbase
  • This is an array - it does not have a value by itself
  • Index is outside the array
  • TJSONbase is not an array and does not support indexes
  • Associative arrays do not support empty index
  • TJSONbase is not an array and does not have Count property
  • Unsupported data type in TJSONbase.JsonText
  • Unexpected character at position
  • Empty element at position
  • Missing closing bracket for array
  • Missing closing bracket for object
  • Unterminated string at position
  • Missing property name/value delimiter (:) at position
  • Missing property value at position
  • Missing fractional part of a floating-point number at position
  • Exponent of the number is not integer at position
  • Unquoted property name at position
  • Control character encountered at position
  • Unrecognized escape sequence at position
  • Invalid UNICODE escape sequence at position
  • Unescaped symbol at position
  • Empty property name at position
  • Expected closing bracket or comma at position

About

JSON library for Delphi

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp