Retrieving json data from web source and parsing it lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- MikeJazz · 2017-02-28 19:21 Hi guys, so I'm fairly new coding in general and I'm look for some help to get me going with getting weather data from http://api.wunderground.com/ap i/Your_Key/features/settings/q/query.format. Now I've filled in the part after .../api/... to reflect what i want to retrieve. Ang just typing it i to a browser i get what I'm looking for. Now the part I need help is sending of the url, and then parsing the .json into variables that i can then use for my nefarious deeds. I have added Synapse to my Lazarus and been playing with it, but to no avail- - Mike ---------------------------------------------------------------------- Phil · 2017-02-28 20:22 Quote from: MikeJazz on February 28, 2017, 08:21:24 pmHi guys, so I'm fairly new coding in general and I'm look for some help to get me going with getting weather data from http://api.wunderground.com/ap i/Your_Key/features/settings/q/query.format. Now I've filled in the part after .../api/... to reflect what i want to retrieve. Ang just typing it i to a browser i get what I'm looking for. Now the part I need help is sending of the url, and then parsing the .json into variables that i can then use for my nefarious deeds. I assume you substituted your own key for "Your_Key", right? With Synapse, you would use the THTTPSend class. Do a GET request with the URL you want to send. If that succeeds, you can then read back the JSON returned. Use FPC's JSON units to parse the JSON returned. Look for examples for how to use Synapse and the JSON units. On a related note, in case you're interested, the ndfd library used with the example apps of Part 3 of the Dynamic Library article series gets weather forecast data from NDFD. It's somewhat different from WU, since it uses the NDFD SOAP service and thus the Web Service Toolkit to make the request. And the data returned is XML, not JSON. But it's there if you have a need for forecast data, in addition to WU historical weather data. https://macpgmr.github.io/ ---------------------------------------------------------------------- sky_khan · 2017-02-28 20:48 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses   fphttpclient, fpjson, jsonparser; procedure TForm1.Button1Click(Sender: TObject);var  Http: TFPHttpClient;  Content : string;  Json : TJSONData; begin  Http:=TFPHttpClient.Create(Nil);  try     Content:=Http.Get('https://jsonplaceholder.typicode.com/users'); //  this is just an example data     JSON:=GetJSON(Content);     try      // You may look http://wiki.freepascal.org/fcl-json to see what you can do with TJSONData     finally       JSON.Free;     end;  finally  Http.Free;  end;end; ---------------------------------------------------------------------- BeniBela · 2017-02-28 22:43 My internet tools put it all together. E.g.: Code: [Select]  uses xquery, xquery_json, synapseinternetaccess;   query('json("http://api.wunderground.com/api/Your_Key/features/setti ngs/q/query.format").forecast.txt_forecast.forecastday(1).fcttext').to String Or step by step: Code: [Select]var   forecasts: IXQValue; begin   forecasts := xqvalue('http://api.wunderground.com/api/Your_Key/featu res/settings/q/query.format').retrieve().map('(.).forecast.txt_forecas t.forecastday()');   forecasts.get(1).getProperty('fcttext').toString;   forecasts.get(2).getProperty('fcttext').toString;   forecasts.get(3).getProperty('fcttext').toString;   ...