Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:09:44+00:00 2026-06-04T23:09:44+00:00

I’m new to JSON and I have this project on my hands that require

  • 0

I’m new to JSON and I have this project on my hands that require me to parse a JSON and display some of its contents in a ListView. The problem is that the documentation I’ve read by now dealt with JSON objects containing JSON arrays, while my case involves dealing with nested objects. To cut the story short, here’s the summary: I’m using Delphi XE2 with DBXJSON. I post some values to a server and it replies with a JSON object that looks like that:

    {
    "products": {
        "Men's Sneakers": {
            "instock": false,
            "size": "423",
            "manufacturer": "Adidas",
            "lastcheck": "20120529"
        },
        "Purse": {
            "instock": true,
            "size": "not applicable",
            "manufacturer": "Prada",
            "lastcheck": "20120528"
        },
        "Men's Hood": {
            "instock": false,
            "size": "M",
            "manufacturer": "Generic",
            "lastcheck": "20120529"
       }
    },
   "total": 41,
   "available": 30
}

What I wanted to achieve was to have each item (i.e. Purse) parsed and added as caption in a listview, along with one subitem (manufacturer). I created a procedure that takes the JSON string as argument, created the JSON object, but I don’t know how to parse the nested objects any further.

procedure TForm1.ParseString(const AString: string);
var
  json          : TJSONObject;
  jPair         : TJSONPair;
  jValue        : TJSONValue;
  jcValue       : TJSONValue;
  l,i           : Integer;
begin
    json    := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(AString),0) as TJSONObject;
  try
    //get the pair to evaluate in this case the index is 1
    jPair   := json.Get(1); 
        {further process the nested objects and adding them to the listview}
  finally
     json.Free;
  end;
end;

Any suggestions would be highly appreciated. Lost quite some time trying to get the ins and outs of JSON in Delphi with no avail.

Thanks,
sphynx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:09:47+00:00Added an answer on June 4, 2026 at 11:09 pm

    Try this sample

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      DBXJSON,
      System.SysUtils;
    
    
    Const
    StrJson=
    '{'+
    '    "products": {'+
    '        "Men''s Sneakers": {'+
    '            "instock": false,'+
    '            "size": "423",'+
    '            "manufacturer": "Adidas",'+
    '            "lastcheck": "20120529"'+
    '        },'+
    '        "Purse": {'+
    '            "instock": true,'+
    '            "size": "not applicable",'+
    '            "manufacturer": "Prada",'+
    '            "lastcheck": "20120528"'+
    '        },'+
    '        "Men''s Hood": {'+
    '            "instock": false,'+
    '            "size": "M",'+
    '            "manufacturer": "Generic",'+
    '            "lastcheck": "20120529"'+
    '        }'+
    '    },'+
    '    "total": 41,'+
    '    "available": 30'+
    '}';
    
    procedure ParseJson;
    var
      LJsonObj  : TJSONObject;
      LJPair    : TJSONPair;
      LProducts : TJSONValue;
      LProduct  : TJSONValue;
      LItem     : TJSONValue;
      LIndex    : Integer;
      LSize     : Integer;
    begin
        LJsonObj    := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(StrJson),0) as TJSONObject;
      try
         LProducts:=LJsonObj.Get('products').JsonValue;
         LSize:=TJSONArray(LProducts).Size;
         for LIndex:=0 to LSize-1 do
         begin
          LProduct := TJSONArray(LProducts).Get(LIndex);
          LJPair   := TJSONPair(LProduct);
          Writeln(Format('Product Name %s',[LJPair.JsonString.Value]));
            for LItem in TJSONArray(LJPair.JsonValue) do
            begin
               if TJSONPair(LItem).JsonValue is TJSONFalse then
                Writeln(Format('  %s : %s',[TJSONPair(LItem).JsonString.Value, 'false']))
               else
               if TJSONPair(LItem).JsonValue is TJSONTrue then
                Writeln(Format('  %s : %s',[TJSONPair(LItem).JsonString.Value, 'true']))
               else
                Writeln(Format('  %s : %s',[TJSONPair(LItem).JsonString.Value, TJSONPair(LItem).JsonValue.Value]));
            end;
         end;
      finally
         LJsonObj.Free;
      end;
    end;
    
    begin
      try
        ParseJson;
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
      Readln;
    end.
    

    This will return

    Product Name Men's Sneakers
      instock : false
      size : 423
      manufacturer : Adidas
      lastcheck : 20120529
    Product Name Purse
      instock : true
      size : not applicable
      manufacturer : Prada
      lastcheck : 20120528
    Product Name Men's Hood
      instock : false
      size : M
      manufacturer : Generic
      lastcheck : 20120529
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.