doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Response not parse Json properly #252

Closed SachinTichkule closed 2 years ago

SachinTichkule commented 2 years ago

i am using simplejson. this is example i have to remove square brackets in response from start and end point. after remove then gonna parse. i checkout in postman this is not from server end response. its from socket.io libraray. its add additional start and end square brackets. please fix this problem.

JSONNode keyValuePairs = new JSONObject();
keyValuePairs.Add("username", userNameInputField.text.Trim());
keyValuePairs.Add("password", passwordInputField.text.Trim());
keyValuePairs.Add("platform", "web");
StringBuilder stringBuilder = null;
await MySocket.socket.EmitAsync(eventName: SocketEvents.login, ack: (response) =>
{
stringBuilder = new StringBuilder(response.ToString());

        // Debug.LogError(response.ToString());
        // string s = response.GetValue<string>();
        // Debug.LogError(s);

        //jsonnode = JSON.Parse(response.GetValue<string>());

    },
       data: keyValuePairs.ToString());

    while (stringBuilder == null)
    {
        await Task.Yield();
    }

    stringBuilder.Remove(0, 1);
    stringBuilder.Remove(stringBuilder.Length - 1, 1);
    jsonnode = JSON.Parse(stringBuilder.ToString());
doghappy commented 2 years ago

Maybe you did it wrong, based on your code, I presume this is what you want.

await MySocket.socket.EmitAsync(eventName: SocketEvents.login, ack: (response) =>
{
    string json = response.GetValue().ToString();
    jsonnode = JSON.Parse(json);
});
SachinTichkule commented 2 years ago

response.GetValue() also workout thanks