JSON superobject (4): add, delete, and modify

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); Procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses superobject; // Add procedure tform1.button1click (Sender: tobject); var JO: isuperobject; I: integer; begin JO: = tsuperobject. create; for I: = 0 to 9 do Jo. I ['n' + inttostr (I)]: = I; showmessage (Jo. asjson (true); for I: = 0 to 9 do Jo. s ['n' + inttostr (I)]: = inttostr (I); showmessage (Jo. asjson (true); for I: = 0 to 9 do Jo. B ['n' + inttostr (I)]: = odd (I); showmessage (Jo. asjson (true); for I: = 0 to 9 do Jo. d ['n' + inttostr (I)]: = I/2; showmessage (Jo. asjson (true); for I: = 0 to 9 do Jo. O ['n' + inttostr (I)]: = So ('{"A": "B"}'); showmessage (Jo. asjson (true); Jo. clear; showmessage (Jo. asjson (true); end; // modify and delete procedure tform1.button2click (Sender: tobject); var JO: isuperobject; STR: string; begin Jo: = So ('{"name": "John", "Age": 88}'); showmessage (Jo. asjson (false, false); Jo. s ['name']: = 'lily'; Jo. I ['age']: = 18; showmessage (Jo. asjson (false, false); Jo. delete ('age'); showmessage (Jo. asjson (false, false); Jo. d ['sizeof]: = 1.83; showmessage (Jo. asjson (false, false); end; // add, delete, modify, and view procedure tform1.button3click (Sender: tobject); var Jo, item: isuperobject; JA: tsuperarray; i: integer; STR: string; begin JO: = So ('{"hobbies": ["programming", "playing"]}'); showmessage (Jo. asjson (false, false); Jo. A ['hobbies ']. add (SO ('Watch TV '); showmessage (Jo. asjson (false, false); JA: = Jo. A ['hobbies ']; Ja. add (SO ('swimming '); showmessage (Jo. asjson (false, false); Ja. insert (0, so ('slee'); showmessage (Jo. asjson (false, false); Ja. delete (0); showmessage (Jo. asjson (false, false); Ja. d [0]: = 3.14; showmessage (Jo. asjson (false, false); Ja. O [0]: = So ('{}'); showmessage (Jo. asjson (false, false); STR: = ''; for I: = 0 to Ja. length-1 do STR: = format ('% S % s', [STR, ja. s [I]); showmessage (TRIM (STR); STR: = ''; for item in Jo ['hobbies '] Do STR: = format ('% S % s', [STR, item. asstring]); showmessage (TRIM (STR); Ja. clear; showmessage (Jo. asjson (false, false); end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.