DIAdem Help

Method: ReadFile for JsonParser

  • Updated2024-09-12
  • 1 minute(s) read

Method: ReadFile for JsonParser

Reads in a string from a JSON file in UTF-8 format.

sReadFile = Object.ReadFile(Filename)
ObjectJsonParser
Object with this method
FilenameString
Specifies the name and the path of the JSON file.
sReadFileString
Contains a JSON string.

The following example reads a JSON file, converts the JSON string into a dictionary object or an array, and displays the size of the dictionary object or array and the JSON string in the log area:

VBScriptPython

 

Dim oJsonParser, sFile, sJsonString, oVbsVariant
Set oJsonParser = CreateJsonParser()
sFile = DataWritePath & "JsonObject.json"
sJsonString = oJsonParser.ReadFile(sFile)
Call oJsonParser.Deserialize(sJsonString, oVbsVariant)
Select Case VarType(oVbsVariant) 
Case vbObject
  Call LogfileWrite("Dictionary size: "  & oVbsVariant.Count)
Case vbArray + vbVariant
  Call LogfileWrite("Array size: "  & UBound(oVbsVariant)+1)
Case Else
  Call MsgBox("Some other data type")
End Select
Call LogfileWrite(sJsonString)

Log in to get a better experience