User Tools

Site Tools


jsonmcjason

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
jsonmcjason [2025/02/09 01:47] – created jwanjsonmcjason [2025/10/10 10:15] (current) – external edit 127.0.0.1
Line 21: Line 21:
 </code> </code>
  
 +Add into json variable
 +<code>
 +   Js.Add('key1').AsInteger := 1;
 +   Js.Add('key2').AsBoolean := True;
 +   Js.Add('key3').AsNumber  := 1.234;
 +   Js.Add('key4').AsString  := 'value 1';
 +   // add an array
 +   Json.Add('array', jitArray);
 +   for i := 1 to 3 do Js['array'].Add.AsInteger := i;
 +</code>
      
 +Check if a key exist
 +<code>
 +   if js.HasKey('key1') then MessageDlg('Key found');
 +</code>
  
 +To update value of key
 +<code>
 +   if js.HasKey(key) then begin
 +      js.Delete(key);
 +      js.Add(key).AsString := value;
 +   end;
 +</code>   
 +
 +To get value of key
 +<code>
 +   ShowMessage(js.Values[key].AsString);
 +</code>
 +
 +Parsing line break solution
 +<code>
 +   js.add(key).asstring := stringreplace(value,slinkbreak,' ',[rfreplaceall]);
 +</code>
 +
 +Check if a string is a valid json
 +<code>
 +   try
 +      js.asjson := '{"i": 123, "f": 123.456, "s": "abc", "b": true, "n": null}';
 +   except
 +      showmessage('not valid json');
 +   end;
 +</code>
 +
 +Display the whole json string
 +<code>
 +   showmessage(js.asjson);
 +</code>
 +
 +More info at https://github.com/hydrobyte/McJSON
jsonmcjason.1739065662.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki