0

I'm using PowerUI and Unity (+Jint built in to powerUI) to attempt to read JSON data coming in from the JavaScript code side, on the C# side. For example, I have some JavaScript code (coming into Unity as a simple string):

var a = importNamespace("Achdus");
a.Heeoolee.Domem({asd:function() {}});

and the C# function that is being called (When this JavaScript code executes through PowerUI and Jint etc....) is this (I already attempted to get the JSON type that comes into the function, which is Dictionary):

namespace Achdus
{

    public static class Heeoolee
    {
        public static void Domem(object obj) {
            if(obj is Dictionary<String, System.Object>) {
                var json = obj as Dictionary<String, System.Object>;
                //now how do I do something like "Jint.Native.Json.Stringify(json)" to get the JSON string?
            }
    }
}

the variable "json" is in fact a valid dictionary that contains the JSON values that are specified in the string, I think that was taken care of automatically with Jint. The problem: I now want to convert that Dictionary back into a simple JSON string. I was looking for a default Jint stringify function that does this, but I could not find one that takes Dictionary as an option.

I can't simply get the string by converting the "object" argument to a string, because the parameter is passed in from JavaScript through Jint as a Dictionary.

There is probably a built in Jint function that could do this, that would be preferable, all I want is a simple reversion of the conversion (#rhyme).

I looked for similar questions regarding converting a general C# object to a JSON string, but Im not sure if the same is possible with a Dictionary in this format.

  • could you convert to a list of keyvaluepairs and then convert the json? - https://stackoverflow.com/questions/4557220/convert-dictionary-to-listkeyvaluepair – Ctznkane525 May 23 '19 at 23:21
  • @Ctznkane525 will this still work if the dictionary's 2nd element "Object" can contain all kinds of things -- from Func to String to numbers to other Dictionarys? and if I do convert it to a list then how can I easily convert that to JSON? – B''H Bi'ezras -- Boruch Hashem May 23 '19 at 23:27

0 Answers0