Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update uJSON.pas #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions uJSON.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ myJSONItem = class
function isNull: boolean;

// Array helper
procedure setArray(newLength: integer);
procedure setArray(newLength: integer);overload;
procedure setArray(const arrayValues: array of myJSONItem);overload;
end;

implementation
Expand Down Expand Up @@ -491,6 +492,10 @@ function myJSONItem.parse(aCode: string): string;
begin
// 1. чистим WS
aCode := wsTrim(aCode);
//Respecting the array format for the parser
if (fType = dtArray) and (aCode[1] <> '[') then
aCode := '['+aCode+']';

// теперь в первом символе наша открывающая скобка
case aCode[1] of
// generic value (text)
Expand Down Expand Up @@ -724,6 +729,23 @@ procedure myJSONItem.setArray(newLength: integer);
self.getElem(newLength - 1);
end;

procedure myJSONItem.setArray(const arrayValues: array of myJSONItem);
var
i : integer;
item : myJSONItem;
begin
//Cleaning the children to include the informed collection
SetLength(fChild, 0);
//Reading the reported items
for i := Low(arrayValues) to High(arrayValues) do
begin
//Adding items to the element tree
item := arrayValues[i];
SetLength(fChild, Length(fChild)+1);
fChild[Length(fChild)-1] := item;
end;
end;

procedure myJSONItem.setBool(value: boolean);
begin
if self = nil
Expand Down Expand Up @@ -824,4 +846,4 @@ procedure myJSONItem.setType(aType: myJDType);
fType := aType;
end;

end.
end.