So. I really tried to find a solution to the problem myself, but I think it was overwhelming. I am trying to send a WebSocket but it gets the same response every time.
I'm using WebSocketSharp and Newtonsoft.Json
My code in C#
sr = new StreamReader("./json1.json");
string output1 = JsonConvert.SerializeObject(sr.ReadToEnd());
ws.Send(output1);
My .json \\ Ps. I'm more than sure that this json is good.
{
"request-type": "StartStopRecording",
"message-id": "1"
}
In console.
output1
"{\r\n \"request-type\": \"StartStopRecording\"\r\n}"
json
{"error":"invalid JSON payload","status":"error"}
So right now i don't have any idea what's wrong.
Maybe I should use something other than Newtonsoft.Json?
CodePudding user response:
I believe the issue is with double serialization. When you read from file with StreamReader, you are getting a string but when you serialize that with NewtonSoft, u double serialize the string.
I would recommend removing the serialization in your code and send the string you get from sr.ReadToEnd
method.