Recent

Author Topic: Search JSON  (Read 846 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Search JSON
« on: July 28, 2020, 11:40:10 am »
Hi All,

I have a json string

Quote
{
   "page": 1,
   "total_results": 1,
   "total_pages": 1,
   "results": [
      {
         "original_name": "Stargate SG-1",
         "genre_ids": [
            10759,
            10765
         ],
         "name": "Stargate SG-1",
         "popularity": 34.789,
         "origin_country": [
            "CA",
            "US"
         ],
         "vote_count": 677,
         "first_air_date": "1997-07-27",
         "backdrop_path": "\/ul7W8lwLIgxre1LXigFw55upfZ5.jpg",
         "original_language": "en",
         "id": 4629,
         "vote_average": 8.1,
         "overview": "The story of Stargate SG-1 begins about a year after the events of the feature film, when the United States government learns that an ancient alien device called the Stargate can access a network of such devices on a multitude of planets. SG-1 is an elite Air Force special operations team, one of more than two dozen teams from Earth who explore the galaxy and defend against alien threats such as the Goa'uld, Replicators, and the Ori.",
         "poster_path": "\/rst5xc4f7v1KiDiQjzDiZqLtBpl.jpg"
      }
   ]
}

My question is how do I get the value of "id"? (value 4629)?

I have attached the JSON as a file.

Thanks in advance.
« Last Edit: July 28, 2020, 01:18:26 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Search JSON
« Reply #1 on: July 28, 2020, 01:38:46 pm »
hello,
to find the first id you can do something like that :
Code: Pascal  [Select][+][-]
  1. program  jsonFinder;
  2. uses Classes, SysUtils,fpjson, jsonparser;
  3. var
  4.   json: tStringlist;
  5.   J,E : TJSONData;
  6. begin
  7.   json:=TStringList.Create;
  8.   json.loadfromfile('out.json');
  9.   J:=GetJSON(json.text);
  10.   E :=  J.FindPath('results[0].id');
  11.   writeln (E.AsJSON);
  12.   json.Free;
  13. end.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Search JSON
« Reply #2 on: July 28, 2020, 02:27:00 pm »
Sorted. Cheers.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018