Jump to content

wright

Members
  • Content Count

    37
  • Joined

  • Last visited

Posts posted by wright


  1. 1 hour ago, programmerdelphi2k said:

    first you need organize your JSON text: many "arrays with sub-arrays..."

    Yes! i did it before i posted but the result was ennoying and shown 0 lines. that's the reason i used the Json data as default.

    image.thumb.png.6865f9e71cfeee33854d5f4d5df7e4d1.png

     

    NB: i forgot to tell that the json data i used is a piece of code from the restaurant project inside Rad Studio samples which uses MongoDB as database: 

    * navigate to: Object Pascal\Database\FireDAC\Samples\DBMS Specific\MongoDB\Restaurants
    * original Json: Object Pascal\Database\FireDAC\DB\Data\restaurants.json

     


  2. Hi there, i tried to parse the selected elements (JSON items), and then display the results using the [TListView](http://docwiki.embarcadero.com/Libraries/en/Vcl.ComCtrls.TListView) component and using using the [TJSONIterator.Next](http://docwiki.embarcadero.com/Libraries/en/System.JSON.Builders.TJSONIterator.Next), [TJSONIterator.Recurse](http://docwiki.embarcadero.com/Libraries/en/System.JSON.Builders.TJSONIterator.Recurse), and [TJSONIterator.Return](http://docwiki.embarcadero.com/Libraries/en/System.JSON.Builders.TJSONIterator.Return) methods.

    Code data:

    {"address": {"building": "1007", "coord": [-73.856077, 40.848447], "street": "Morris Park Ave", "zipcode": "10462"}, "borough": "Bronx", "cuisine": "Bakery", "grades": [{"date": {"$date": 1393804800000}, "grade": "A", "score": 2}, {"date": {"$date": 1378857600000}, "grade": "A", "score": 6}, {"date": {"$date": 1358985600000}, "grade": "A", "score": 10}, {"date": {"$date": 1322006400000}, "grade": "A", "score": 9}, {"date": {"$date": 1299715200000}, "grade": "B", "score": 14}], "name": "Morris Park Bake Shop", "restaurant_id": "30075445"}
    {"address": {"building": "469", "coord": [-73.961704, 40.662942], "street": "Flatbush Avenue", "zipcode": "11225"}, "borough": "Brooklyn", "cuisine": "Hamburgers", "grades": [{"date": {"$date": 1419897600000}, "grade": "A", "score": 8}, {"date": {"$date": 1404172800000}, "grade": "B", "score": 23}, {"date": {"$date": 1367280000000}, "grade": "A", "score": 12}, {"date": {"$date": 1336435200000}, "grade": "A", "score": 12}], "name": "Wendy'S", "restaurant_id": "30112340"}
    {"address": {"building": "351", "coord": [-73.98513559999999, 40.7676919], "street": "West   57 Street", "zipcode": "10019"}, "borough": "Manhattan", "cuisine": "Irish", "grades": [{"date": {"$date": 1409961600000}, "grade": "A", "score": 2}, {"date": {"$date": 1374451200000}, "grade": "A", "score": 11}, {"date": {"$date": 1343692800000}, "grade": "A", "score": 12}, {"date": {"$date": 1325116800000}, "grade": "A", "score": 12}], "name": "Dj Reynolds Pub And Restaurant", "restaurant_id": "30191841"}
    {"address": {"building": "2780", "coord": [-73.98241999999999, 40.579505], "street": "Stillwell Avenue", "zipcode": "11224"}, "borough": "Brooklyn", "cuisine": "American ", "grades": [{"date": {"$date": 1402358400000}, "grade": "A", "score": 5}, {"date": {"$date": 1370390400000}, "grade": "A", "score": 7}, {"date": {"$date": 1334275200000}, "grade": "A", "score": 12}, {"date": {"$date": 1318377600000}, "grade": "A", "score": 12}], "name": "Riviera Caterer", "restaurant_id": "40356018"}
    {"address": {"building": "97-22", "coord": [-73.8601152, 40.7311739], "street": "63 Road", "zipcode": "11374"}, "borough": "Queens", "cuisine": "Jewish/Kosher", "grades": [{"date": {"$date": 1416787200000}, "grade": "Z", "score": 20}, {"date": {"$date": 1358380800000}, "grade": "A", "score": 13}, {"date": {"$date": 1343865600000}, "grade": "A", "score": 13}, {"date": {"$date": 1323907200000}, "grade": "B", "score": 25}], "name": "Tov Kosher Kitchen", "restaurant_id": "40356068"}
    
    procedure TForm2.AddColumn(const AName: String);
    var
      oCol: TListColumn;
    begin
      oCol := ListView1.Columns.Add;
      oCol.Width := -1;
      oCol.Caption := AName;
    end;
    
    procedure TForm2.Button3Click(Sender: TObject);
    begin
      ParseObject;
    end;
    
    procedure TForm2.ParseObject;
    var
      oIter: TJSONIterator;
      LJsonTextReader: TJsonTextReader;
      LStringReader: TStreamReader;
      oItem: TListItem;
      I: Integer;
    begin
    
    //  oIter := TJSONIterator.Create(LJsonTextReader);
    //  NObjJSON := oIter.AsInteger;
    
      ListView1.Items.Clear;
      ListView1.Columns.Clear;
      ListView1.ViewStyle := vsReport;
      AddColumn('Name');
      AddColumn('Cuisine');
      AddColumn('Street');
      AddColumn('Building');
      AddColumn('Borough');
      ListView1.Items.BeginUpdate;
      try
        oItem := ListView1.Items.Add;
        for i := 1 to ListView1.Columns.Count - 1 do
          oItem.SubItems.Add('');
    
        LStringReader := TStreamReader.Create('../../resto.json', TEncoding.UTF8, True);
        LJsonTextReader := TJsonTextReader.Create(LStringReader);
        oIter := TJSONIterator.Create(LJsonTextReader);
    
        try
          while True do
          begin
            while oIter.Next do
              if oIter.&Type in [TJsonToken.StartObject, TJsonToken.StartArray] then
                oIter.Recurse
              else if oIter.Path = 'name' then
                oItem.Caption := oIter.AsString
              else if oIter.Path = 'cuisine' then
                oItem.SubItems[0] := oIter.AsString
              else if oIter.Path = 'address.street' then
                oItem.SubItems[1] := oIter.AsString
              else if oIter.Path = 'address.building' then
                oItem.SubItems[2] := oIter.AsString
              else if oIter.Path = 'borough' then
                oItem.SubItems[3] := oIter.AsString;
            if oIter.InRecurse then
              oIter.Return
            else
              Break;
          end;
        finally
          oIter.Free;
          LJsonTextReader.Free;
          LStringReader.Free;
        end;
      finally
        ListView1.Items.EndUpdate;
      end;
    end;

    As Result: i only got one line filled.

    image.thumb.png.e2df45f6ba631fb0226209f0e76ea712.png

     

    I would like to get the result like that:

    Expected behavior

    image.thumb.png.9a7293d8e3bcf58810ff06f4f8b2b6ee.png


  3. 1 hour ago, FPiette said:

    You can check a host name resolution to IP address using Windows command line nslookup.

    I did: ws.twelvedata.com  is has 4 IP addresses. But ws.xn--twelvedata-lb99c.com is not a valid hostname. That's your problem and NOT an ICS issue!

    First thing first : check the hostname you use...

     

    As @Angus Robertson reported; 

     

    1 hour ago, Angus Robertson said:

    When I first tried ws.twelvedata.com ICS gave the error 'Cannot convert host address 'ws.xn--twelvedata-lb99c.com' - Host not found ' (as your screen short) which means the host name contains illegal characters and has been translated into ASCII, note the xn- part

    so i followed what you suggested. i got no error know but no connection or it seems attempting to connect. (Port 80 even with 443) 


  4. Hey there! following the documentation of TWSocket.Addr, i tried to connect to a WebSocket "wss://ws.twelvedata.com/v1/quotes/price?apikey=api_key" using the "C:\Users\Public\...\icsv870\Samples\Delphi\SslInternet\OverbyteIcsSimpleSslCli64.dproj".

    without success. i always got error like:  'Winsock Resolve Host: Cannot convert host address 'wss://ws.twelvedata.com/v1/quotes/price?apikey=api_key' - Host not found (#11001)'. Processus OverbyteIcsSimpleSslCli.exe (25544)

     

    can you point me to the right direction? thx


  5. Hello,
    I am learning to use the TJSONIterator(Readers and Writers JSON Framework) under delphi 10.3.3 and I found a russian link putting this into practice through the creation of an application assessing the negative impact on the environment: https://webdelphi.ru/. 

    Firstly, i have a custom class definition named "NVOS.JsonParser.pas" and the "open-data-1.json" file, i don't know how to proceed

    However, I can't figure out already knowing that the result should look like: "App.png". 

     

    App.png

    open-data-1.json

×