Skip to content
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

Error on serializing response #48

Open
Hailiebaby16 opened this issue Mar 8, 2023 · 5 comments
Open

Error on serializing response #48

Hailiebaby16 opened this issue Mar 8, 2023 · 5 comments

Comments

@Hailiebaby16
Copy link

I'm tryring your sample code and i got this error
Severity Code Description Project File Line Suppression State Error CS0012 The type 'JsonElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Text.Json, Version=6.0.0.4
and

Severity Code Description Project File Line Suppression State Error CS0411 The type arguments for method 'SocketIOResponse.GetValue<T>(int)' cannot be inferred from the usage. Try specifying the type arguments explicitly
from this line of code.

ReceivedText.text += "Received On " + name + " : " + response.GetValue().GetRawText() + "\n";

@itisnajim
Copy link
Owner

response.GetValue().GetRawText() become response.ToString(), i didn't update the example folder, sorry !

@Hailiebaby16
Copy link
Author

Bro what if the response is an array of int. How can i get their values?

response.GetValue().GetRawText() become response.ToString(), i didn't update the example folder, sorry !

@itisnajim
Copy link
Owner

var obj = response.GetValue<YOUR_TYPE>();

replace YOUR_TYPE with the class name or the type you want to serialize to
e.g YOUR_TYPE can be: string[], SomeClass, int and so on

already mentioned in the Readme:
https://github.com/itisnajim/SocketIOUnity#receiving

@Hailiebaby16
Copy link
Author

var obj = response.GetValue<YOUR_TYPE>();

replace YOUR_TYPE with the class name or the type you want to serialize to e.g YOUR_TYPE can be: string[], SomeClass, int and so on

already mentioned in the Readme: https://github.com/itisnajim/SocketIOUnity#receiving

I've tried doing that but it gives me error. The only time i dont have error is when i use IList as my class but not able to access the value

@itisnajim
Copy link
Owner

check if the server send the correct data, maybe its a string rather that list of objects,
this is not a list => "["item1", "item2"]"

and i recommend to use a list wrapper instead of a direct list
e.g a class named StringsList that has a property data of type string[]

without a debug log or a snippet of code i can't tell whats the cause of your problem.

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

2 participants