Jump to content

Search the Community

Showing results for tags 'tlistviewitem'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 1 result

  1. 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. I would like to get the result like that: Expected behavior
×