Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic json examples
#4
Ron you can use Chilkat with qm to process json data. there is an activex com component or a .net version. The .net version is a bit easier but requires you to use CsScript.

here is all your request using the ChilkatDotNet47.dll .Just place it in qm program folder
here is the zip file containing the dll.

.zip   chilkatdotnet47-9.5.0-win32.zip (Size: 3.2 MB / Downloads: 384)
Function ChilkatJsonExamples
Code:
Copy      Help
out
str json=
;{
;;;;"version": 4,
;;;;"lastUserContextId": 1,
;;;;"identities": [{
;;;;;;;;;;;;"userContextId": 1,
;;;;;;;;;;;;"public": false,
;;;;;;;;;;;;"icon": "txt",
;;;;;;;;;;;;"color": "",
;;;;;;;;;;;;"name": "test 1",
;;;;;;;;;;;;"accessKey": ""
;;;;;;;;}, {
;;;;;;;;;;;;"userContextId": 2,
;;;;;;;;;;;;"public": false,
;;;;;;;;;;;;"icon": "txt",
;;;;;;;;;;;;"color": "",
;;;;;;;;;;;;"name": "test 2",
;;;;;;;;;;;;"accessKey": ""
;;;;;;;;}, {
;;;;;;;;;;;;"userContextId": 3,
;;;;;;;;;;;;"public": false,
;;;;;;;;;;;;"icon": "txt",
;;;;;;;;;;;;"color": "blue",
;;;;;;;;;;;;"name": "test 3"
;;;;;;;;}
;;;;]
;}

CsScript x
x.SetOptions("references=C:\Program Files (x86)\Quick Macros 2\ChilkatDotNet47.dll")
x.AddCode("")

;call static function
str R=x.Call("Class1.TestFunction" json)
out R


#ret
//C# code
using System;
using Chilkat;

public class Class1
{
,public static string TestFunction(string s)
,{
,,Chilkat.JsonObject json = new Chilkat.JsonObject();
,,bool success = json.Load(s);
,,Chilkat.JsonArray tagsArray = json.ArrayOf("identities");
,,Console.WriteLine("Remove whole json object userContextId': 3 and output result");
,,tagsArray.DeleteAt(2);
,,json.EmitCompact = false;
,,Console.WriteLine(json.Emit());
,,Console.WriteLine("Add object and output result");
,,json.UpdateString("identities[2].userContextId","7");
,,json.UpdateBool("identities[2].public",true);
,,json.UpdateString("identities[2].icon","doc");
,,json.UpdateString("identities[2].color","red");
,,json.UpdateString("identities[2].name","test 7");
,,json.UpdateString("identities[2].accessKey","123");
,,json.EmitCompact = false;
,,Console.WriteLine(json.Emit());    
,,Console.WriteLine("Modify key-value pair, of ''userContextId'': 1,''  ---> modify name from ''test 1'' to ''test 1B''");
,,json.UpdateString("identities[0].name","test 1B");
,,json.EmitCompact = false;
,,Console.WriteLine(json.Emit());        
,,return "finished";
,}
}


Messages In This Thread
Basic json examples - by r0n - 06-14-2021, 09:19 PM
RE: Basic json examples - by Gintaras - 06-15-2021, 07:25 PM
RE: Basic json examples - by r0n - 06-15-2021, 07:43 PM
RE: Basic json examples - by Kevin - 06-16-2021, 09:23 PM
RE: Basic json examples - by Kevin - 06-16-2021, 11:12 PM
RE: Basic json examples - by r0n - 06-17-2021, 05:31 AM
RE: Basic json examples - by stupomer - 04-07-2022, 05:10 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)