Hi experts, I wanted to read and work with JSON files. Is there best ways to read JSON files using TestComplete? I wanted to trigger the script to fetch the JSON file and do curtains operation by...
You browse to the location of your desired dll(s) and load it(them) in.
Then in your code (I use JavaScript) you can call static methods or instantiate an object through the dotNet object. Note: scripting languages like Javascript don’t support method overloading, so for each constructor method you will see zctor(), zctor_1(), zctor_2(), etc. where each will show you the needed parameters.
Below is sample code that writes a JSON file. You might need to add a reference to System.Runtime.dll to access string builder, text writer and file writer.
function NewtonSoft()
{
var sb = dotNET.System_Text.StringBuilder.zctor();
var sw = dotNET.System_IO.StringWriter.zctor_3(sb);
var jtw = dotNET.Newtonsoft_Json.JsonTextWriter.zctor(sw);
jtw.WriteStartObject();
jtw.WritePropertyName("Make");
jtw.WriteValue_33("Porsche");
jtw.WritePropertyName("Model");
jtw.WriteValue_33("911 GT3");
jtw.WritePropertyName("Engine");
jtw.WriteStartArray();
jtw.WriteValue_33("4.0L");
jtw.WriteComment("(640bhp)");
jtw.WriteEnd();
jtw.WritePropertyName("Transmission");
jtw.WriteStartArray();
jtw.WriteValue_33("6 Speed");
jtw.WriteValue_33("Manual");
jtw.WriteEnd();
jtw.WriteEndObject();
dotNET.System_IO.File.WriteAllText("C:\\test.txt", sb.ToString());
}