Skip to content

Multiple Classes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Weaver1911 opened this issue Jan 14, 2021 · 3 comments
Open

Multiple Classes #1

Weaver1911 opened this issue Jan 14, 2021 · 3 comments

Comments

@Weaver1911
Copy link

Hello there.
1st of all, i want to thank you about this tool. That's exactly what i wanted to create and i've failed -many times-.
This is not a simple HTTP server. It's gem.
But I'm trying to do something like this

 public MyClassCollection C1()
    {
        MyClassCollection result = new MyClassCollection
        {
            _Class2_data.MyFloat = 0.5f,
            _Class2_data.MyInt = 1,
            _Class2_data.MyString = "This is a test",
            
            _Class2_data._Class3_data.MyFloat1 = 0.5f,
            _Class2_data._Class3_data.MyInt1 = 1,
            _Class2_data._Class3_data.MyString1 = "This is a test 2"
        };
        return result;
    }

    public class MyClassCollection
    {
        public MyClass2 _Class2_data;

    }

    public class MyClass2
    {
        public float MyFloat;
        public int MyInt;
        public string MyString;
        public MyClass3 _Class3_data;
    }

    public class MyClass3
    {
        public float MyFloat1;
        public int MyInt1;
        public string MyString1;
    }

And seems to be impossible. Am i missing something?
Or maybe Is there any other way i can use to achieve that result ?

In reality is use 3rd party software to put values there like this
_Class2_data.MyFloat = MySoftwareOutput.value,

Thanks in advance.

@sableangle
Copy link
Owner

Hi!

Are you wish to use "MyClassCollection" as a custom object return?
The custom object return require the object which is supported by the JSON library your are using.

The SimpleHTTPServer use the Unity's JsonUtility as the default JSON library.
According to the Unity's manual, JsonUtility based on the Unity's serialization, so maybe add [System.Serializable] attribute on your custom class makes it become serailizable will fix the problem.

In the other hand, have you try using LitJson library, and is there same problem when using LitJson? LitJson has better compatibility than JsonUtility on serialize to Json string, I thing the problem should not exist when using LitJson.
(Add "UseLitJson" define symbol in your ProjectSetting and add LitJson.dll in Assets/Plugins folder)

If the problem still exist, could you please give me the console log, exception message or any error msg about issue.
It will be a great help for fix.

@Weaver1911
Copy link
Author

Hello sableangle.

sorry about that huge delay, I was really busy with other stuff.

Yes this is what i want to achieve. And yes i use JsonUtility by Unity. I don't exactly know what is the problem, Since i've already deserialized the Json and it's working as intended.

I've tried the LitJson too. Like this:
Screenshot_3
But nothing changed. still the same errors were there.
Screenshot_4

And this is how the errors in my code looks like
Screenshot_1
Screenshot_2

I really don't understand what to do.
Hope that helps you understand what i'm doing wrong. I'm not experienced with Json that much.

@orangeagain
Copy link
Contributor

try offical new netwtonjson libray might be useful:https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@3.0/manual/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants