I have encountered a strange issue that is really frustrating. It all started when I noticed that my Json.Parse function failed intermittently. Here is the code snippet in question:
const Info = JSON.parse(response);
this.onInfoUpdate(Info.InfoConfig[0]);
The responses I get are as follows:
"{\"InfoConfig\":[{\"InfoId\":1,\"InfoName\":\"Derp\",\"Pid\":0,\"StartDate\":\"2018-10-31T00:00:00\",\"EndDate\":\"2018-11-10T00:00:00\",\"InclusiveFilters\":null,\"ExlusiveFilters\":null,\"Type\":0}],\"InfoIds\":["1"],\"Guid\":\"2#myman\"}"
This response cannot be parsed to a Json object. I am puzzled by why it sometimes removes the backslashes and doesn't enclose the whole array in quotes.
{"InfoConfig":[{"InfoId":1,"InfoName":"Derp","Pid":0,"StartDate":"2018-10-31T00:00:00","EndDate":"2018-11-10T00:00:00","InclusiveFilters":null,"ExlusiveFilters":null,"Type":0}],"InfoIds":["1"],"Guid":"2#myman"}
The second response works fine, where JSON.parse successfully converts it to a Json object. However, there are times when I receive a different response.
This is the section responsible for sending data to the frontend:
case HiveMessageType.PlayerInfo:
var playerNotification = (PlayerInfoNotificationModel)message;
var InfoIds = JsonConvert.SerializeObject(playerNotification.InfoIds);
var serializedListWithInfo = JsonConvert.SerializeObject(playerNotification);
SignalRClient.SendAsync("RegisterUserToMultipleGroups", playerNotification.Guid, InfoIds, serializedListWithInfo);
break;