1. I am using webrequests to get a json file in python. I now want to deserialize that json string into an object.
    Now in C# this would be no issue as you can just use Newtonsoft.Json however there is no python equivalent due to import restrictions. How can I get around this?

    Things i've tried:
    • Searched the forums and unity support sites to no avail
    • Importing the json module for python (it's not allowed)
    • Decompiled every DLL using iSpy to find a json deserializer to no avail
    Please tell me i'm missing something obvious. Many Thanks!
     
  2. Oxide uses IronPython, so you can presumably use Newtonsoft.Json for the Python extension as well.
    There's a DeserializeObject with a type parameter and one without a type parameter that serializes to "object".
    For the one with a type parameter you obviously need to provide a type, which you can use [T] for in IronPython (e.g. Action[T]). This should work for parameterized methods as well.
    You might want to try with the C# Dictionary type from System.Collections.Generic
    (e.g. something along the lines of DeserializeObject[Dictionary[string, object]](s) or similar), as IronPython can work with that and will convert that to a IronPython.Runtime.PythonDictionary.
    The only thing I'm not sure about is whether IronPython allows you to use parameterized methods and whether you can supply "object" (maybe you can supply a better type in your concrete use case if it doesn't work?).
    If none of this works, you can try using the DeserializeObject without a type parameter. It deserializes to "object", however I don't know the runtime type (maybe dictionary?) as it isn't documented and I'd have to dig through the Newtonsoft.Json source code now.
    Let me know if you got it to work, also keep in mind that Oxide might drop the python extension from the official install in a while.
     
  3. Thanks for having a loot into it sqroot, I have tried using
    Code:
    import Newtonsoft.Json
    however it just disallows the import. I was fearing that the python extension would be dropped in time, which would be a shame. As for the types I have used the C# types before and they work - it's just that I have no method of accessing the Json module of Newtonsoft :(
     
  4. Importing in IronPython works differently.
    You cannot import C# namespaces, you need to import concrete c# classes, e.g. Newtonsoft.Json.JsonConvert.
    The python extension mistakenly reports that the respective import is blacklisted when the import just isn't possible, because IronPython cannot import namespaces.
    This has annoyed me a bunch of times as well ;)
    There's a bunch of other issues with the extension that aren't that nice either (because it isn't well maintained), such as that serializing and deserializing python lists when using config files isn't possible (should use tuples instead).
    This is one of the reasons why the extension might be dropped from the official install (support will be kept for private plugins as the scripting languages are mostly used there).