0

I'm create a connection to websocket server in Unity by using System.Net.Websockets. I have a JSON array with variables. Actually, i can send a JSON file. But, when i try read what server responds (my server respond me what i send to him) i have a just JSON array. I want read each variable and equals each of them to values, which i created before sending. For example: before sending(PlayerName: "Name", Money: 200), server respond (PlayerName: "Name", Money: 200)

Part of code, where i had from server undecoded JSON Debug.Log("Server responds: " + Encoding.UTF8.GetString(buf.Array, 0, r.Count));

Here all of my code https://pastebin.com/Ht6hmkgs

When i try a read JSON - in Unity console i have just a array of values, like this

{\"name\":\"PlayerName\",\"money\":200}
redOrange
  • 1
  • 1
  • 3
    Possible duplicate of [Serialize and Deserialize Json and Json Array in Unity](https://stackoverflow.com/questions/36239705/serialize-and-deserialize-json-and-json-array-in-unity) – Ryanas Aug 28 '19 at 10:29
  • 1
    you already used `JsonUtility.ToJson` .. what hinders you from using [`JsonUtility.FromJson`](https://docs.unity3d.com/ScriptReference/JsonUtility.FromJson.html) or [`FromJsonOverwrite`](https://docs.unity3d.com/ScriptReference/JsonUtility.FromJsonOverwrite.html) when going the other way round? if having trouble because it is a thread [this](https://stackoverflow.com/a/57685239/7111561) might help – derHugo Aug 28 '19 at 10:31
  • Well you have performed just the translation from bytes to a `Json` string.Now you need to deserialize the string to an actual object.Check out this [material](https://docs.unity3d.com/Manual/JSONSerialization.html). – Bercovici Adrian Sep 02 '19 at 11:56

0 Answers0