You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
publicMyClassCollectionC1(){MyClassCollectionresult=newMyClassCollection{_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"};returnresult;}publicclassMyClassCollection{publicMyClass2_Class2_data;}publicclassMyClass2{publicfloatMyFloat;publicintMyInt;publicstringMyString;publicMyClass3_Class3_data;}publicclassMyClass3{publicfloatMyFloat1;publicintMyInt1;publicstringMyString1;}
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,
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.
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:
But nothing changed. still the same errors were there.
And this is how the errors in my code looks like
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.
Activity
sableangle commentedon Jan 14, 2021
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 commentedon Feb 8, 2021
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:


But nothing changed. still the same errors were there.
And this is how the errors in my code looks like


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 commentedon Apr 15, 2022
try offical new netwtonjson libray might be useful:https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@3.0/manual/index.html