View Only
  • 1.  Using Newtonsoft Library in Global Methods

    Posted 24 days ago
    Got another head scratcher.

    Is there any way to leverage a library for scripting? I figure the answer is probably a resounding "no" but was curious if anyone has found a workaround that allows me to parse a JSON in any way other than a series of janky "string.indexof()" commands.  I had success getting XPression to send a request to generate an oauth token on an external server as a JSON response but parsing the response is far less elegant without a dedicated JSON parsing library (for what its worth, it is working, but I want to do this cleaner next time). 

    Anyone had success with non-system libraries in VB?


    Nick Huntley

  • 2.  RE: Using Newtonsoft Library in Global Methods

    Posted 24 days ago
    This works to load the assembly manually. Note, I could only get it to work with the .NET 2.0 version. Tested with Xpression Developer 10.0

        Dim jsonLib As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("<your path>\Newtonsoft\Bin\net20\Newtonsoft.Json.dll")
        Dim jtype = jsonLib.GetType("Newtonsoft.Json.Linq.JObject")
        Dim obj = Activator.CreateInstance(jtype)
        ' Test it out

        Dim myJsonObj = obj.Parse("{""a"":123}") ' Your json string goes here
        Engine.DebugMessage(myJsonObj("a"), 0)  ' Logs "123"
    Catch ex As Exception
        Engine.DebugMessage(ex.Message, MessageType.mt_Error)
    End Try

    Another, maybe simpler option is to save the downloaded JSON to a file using 

    System.IO.File.WriteAllText(pathToJsonFile, downloadedJsonText)

    Then set up a JSON Datalinq Source to monitor the file and set the elements in your scene to use that.