Skip to content

Multiple Classes  #1

Open
Open

Description

@Weaver1911

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.

Activity

  1. sableangle commented on Jan 14, 2021

    @sableangle
    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.

  2. Weaver1911 commented on Feb 8, 2021

    @Weaver1911
    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.

  3. orangeagain commented on Apr 15, 2022

    @orangeagain
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions