Difference between revisions of "Talk:link"
From Free Pascal wiki
Jump to navigationJump to search (Confirmation and example with small modifications) |
|||
Line 5: | Line 5: | ||
::I plan to remove this page... --[[User:Bart|Bart]] ([[User talk:Bart|talk]]) 22:34, 5 December 2017 (CET) | ::I plan to remove this page... --[[User:Bart|Bart]] ([[User talk:Bart|talk]]) 22:34, 5 December 2017 (CET) | ||
+ | |||
+ | ::: Perfectly ok with me Bart, as currently this page makes no sense. For the record i post below a small modified version of [[user:Tudi x]]'s work, so that his example would be more in line with the first example on the [[fcl-json]] page. Feel free to abuse --[[User:Molly|Molly]] ([[User talk:Molly|talk]]) 02:18, 6 December 2017 (CET) | ||
+ | |||
+ | <syntaxhighlight> | ||
+ | uses | ||
+ | Classes, TypInfo, fpjson, jsonparser; | ||
+ | |||
+ | procedure JSONItems(Info: TStrings); | ||
+ | var | ||
+ | jData : TJSONData; | ||
+ | jItem : TJSONData; | ||
+ | i, j: integer; | ||
+ | object_name, field_name, field_value, object_type, object_items: string; | ||
+ | begin | ||
+ | jData := GetJSON('{"A":{"field1":0, "field2": false},"B":{"field1":0, "field2": false}}'); | ||
+ | |||
+ | for i := 0 to jData.Count - 1 do | ||
+ | begin | ||
+ | jItem := jData.Items[i]; | ||
+ | |||
+ | object_type := GetEnumName(TypeInfo(TJSONtype), Ord(jItem.JSONType)); | ||
+ | object_name := TJSONObject(jData).Names[i]; | ||
+ | WriteStr(object_items, jItem.Count); | ||
+ | |||
+ | Info.Append('object type: ' + object_type + '|object name: ' + object_name + '|number of fields: ' + object_items); | ||
+ | |||
+ | for j := 0 to jItem.Count - 1 do | ||
+ | begin | ||
+ | field_name := TJSONObject(jItem).Names[j]; | ||
+ | field_value := jItem.FindPath(TJSONObject(jItem).Names[j]).AsString; | ||
+ | |||
+ | Info.Append(field_name + '|' + field_value); | ||
+ | end; | ||
+ | end; | ||
+ | |||
+ | jData.Free; | ||
+ | end; | ||
+ | </syntaxhighlight> |
Revision as of 03:18, 6 December 2017
What exactly is the purpose of this page?
Why is it called "link"??? --Bart (talk) 22:29, 4 December 2017 (CET)
- in case user:Tudi x is reading this, i would have used the fcl-json page to add your example or provided a complete example posted in the category code examples. I am assuming that author is new to editing wiki's and/or simply missed the fcl-json page. --Molly (talk) 23:30, 4 December 2017 (CET)----
- Perfectly ok with me Bart, as currently this page makes no sense. For the record i post below a small modified version of user:Tudi x's work, so that his example would be more in line with the first example on the fcl-json page. Feel free to abuse --Molly (talk) 02:18, 6 December 2017 (CET)
uses
Classes, TypInfo, fpjson, jsonparser;
procedure JSONItems(Info: TStrings);
var
jData : TJSONData;
jItem : TJSONData;
i, j: integer;
object_name, field_name, field_value, object_type, object_items: string;
begin
jData := GetJSON('{"A":{"field1":0, "field2": false},"B":{"field1":0, "field2": false}}');
for i := 0 to jData.Count - 1 do
begin
jItem := jData.Items[i];
object_type := GetEnumName(TypeInfo(TJSONtype), Ord(jItem.JSONType));
object_name := TJSONObject(jData).Names[i];
WriteStr(object_items, jItem.Count);
Info.Append('object type: ' + object_type + '|object name: ' + object_name + '|number of fields: ' + object_items);
for j := 0 to jItem.Count - 1 do
begin
field_name := TJSONObject(jItem).Names[j];
field_value := jItem.FindPath(TJSONObject(jItem).Names[j]).AsString;
Info.Append(field_name + '|' + field_value);
end;
end;
jData.Free;
end;