Recent

Author Topic: Parsing with JSON String without saving it in file.  (Read 276 times)

BSaidus

  • Sr. Member
  • ****
  • Posts: 469
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Parsing with JSON String without saving it in file.
« on: February 09, 2023, 04:58:28 pm »
Hello.
I have a web service ( written in lazarus/fpc), one of the functions of this webservice is to send me back a small json file which content is :
Code: Text  [Select][+][-]
  1. {
  2.     "system": {
  3.         "name": "pp1",
  4.         "version": "13.1",
  5.         "hostname": "uc1"
  6.     },
  7.     "config": {
  8.         "physical": {
  9.             "comments": "this is a comment",
  10.             "count": "12",
  11.             "activated": "2",
  12.             "AItem0": {
  13.                 "active": "1",
  14.                 "kername": "itm0"
  15.             },
  16.             "AItem1": {
  17.                 "active": "1",
  18.                 "kername": "itm0"
  19.             }
  20.         }
  21.     }
  22. }
  23.  
I use Indy IdHttp to retreive this resourse.
Code: Pascal  [Select][+][-]
  1. var
  2.   jsstr: String;
  3. begin
  4.   jsstr := IdHttp1.Post(s_URL, sParam) ;  // s_URL = url to webservice, sParam = parameters needed.
  5. end;
  6.  

My question is, is there any simple way out of the way of saving the String into json file and use
Code: Pascal  [Select][+][-]
  1. GetValue('/config/physical/AItem0/active')
of the TJSConfig.

In other worlds, is there a way to parse the string and get all elements without saving it into file and do with TJsConfig.

Thank you.
« Last Edit: February 09, 2023, 09:18:34 pm by BSaidus »
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

BSaidus

  • Sr. Member
  • ****
  • Posts: 469
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Parsing with JSON String without saving it in file.
« Reply #1 on: February 09, 2023, 10:11:02 pm »
Hhhh, I found the way.
Code: Pascal  [Select][+][-]
  1.  
  2.   GetJSON(jsstr).FindPath('config.physical.AItem0.kername').AsString );
  3.  
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018