Recent

Author Topic: How to MERGE TJSONData variables  (Read 1715 times)

DeBritto

  • Jr. Member
  • **
  • Posts: 68
How to MERGE TJSONData variables
« on: November 16, 2018, 10:24:42 pm »
Hi Folks,
I need to merge some JSON variables into one string only. I'm using "fpjson" and "jsonparser" units.

Like this:
Code: Pascal  [Select][+][-]
  1.  
  2. ZDataItems := HTTPClient.Get('https://api.zotero.org/groups/' + jElementGroups.FindPath('id').AsString + '/collections/' + jElementCollection.FindPath('key').AsString + '/items?start=0&limit=100' + zReadAPI_key);
  3.  
  4. jDataCollectionItems := GetJSON( ZDataItems );
  5.  
  6. ZDataItems := HTTPClient.Get('https://api.zotero.org/groups/' + jElementGroups.FindPath('id').AsString + '/collections/' + jElementCollection.FindPath('key').AsString + '/items?start=100&limit=100' + zReadAPI_key);
  7.  
  8. jDataCollectionItems := jDataCollectionItems + GetJSON( ZDataItems );
  9.  

Something like this...

How can I do this?

Warm regards
« Last Edit: November 16, 2018, 10:56:37 pm by DeBritto »

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: How to MERGE TJSONData variables
« Reply #1 on: November 16, 2018, 11:42:37 pm »
convert json to string?
https://www.freepascal.org/docs-html/fcl/fpjson/tjsondata.asjson.html

if you want to merge the 2 arrays, just add the second array to the first, I don't remember if one by one, or all at once with any function

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: How to MERGE TJSONData variables
« Reply #2 on: November 17, 2018, 12:42:21 pm »
Incomprehensible scheme of the enterprises and the type of each of their parts. That is,
Code: Text  [Select][+][-]
  1. A={"B_name": B,"C_name": C}
or
Code: Text  [Select][+][-]
  1. A=[B, C]
. Depending on what result you want and will be a warm. In the first case the result will be a JSON object, in the second JSON array

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: How to MERGE TJSONData variables
« Reply #3 on: November 17, 2018, 12:50:13 pm »
For example, if the "sum" of the merge must be a JSON object, something like this would be:
Code: Pascal  [Select][+][-]
  1. function JSONUnion(AJSONData, BJSONData: TJSONData): TJSONObject;
  2. begin
  3. ... ...
  4.   Result:=TJSONObject.Create;
  5.   with Result do
  6.   begin
  7.       Add('A_element', AJSONData);
  8.       Add('B_element', BJSONData);
  9.   end
  10. end;
  11.  
  12. ...
  13. S:=JSONUnion.AsJSON;
  14.  

 

TinyPortal © 2005-2018