1

I'm trying to parse JSON string that received from websocket sharp but keep failing.

using (var ws = new WebSocket(WebAddr))
{
    ws.Log.Level = LogLevel.Debug;
    ws.OnOpen += (ss, ee) =>
    {
        System.IO.File.WriteAllText(@"C:\log.txt", "connected!");
    };
    ws.OnMessage +=  (ss, ee) =>
    {
        JsonValue jo = JsonValue.Parse(ee.Data);
        string value = (string)jo["levelid"];
        Console.Write(value + '\n');
    };
}

It just threw exception error when reaches string value... part.

I'm using System.Json from nuget.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Rocky Wei
  • 15
  • 1
  • 8

1 Answers1

0

I think I figured it out. The server will respond with 2 messages, one is Json object and one is Json array.

dynamic jo = JsonConvert.DeserializeObject(ee.Data);

This fixed my problem!

Rocky Wei
  • 15
  • 1
  • 8