I am communicating with a third-party API that returns JSON responses as follows:
"{\"SomeResponse\":{\"FIrstAttribute\":8,\"SecondAttribute\":\"On\",\"ThirdAttribute\":{\"Id\":2,\"FirstName\":\"Okkie\",\"Name\":\"Bokkie\",\"Street\":\"\",\"StreetNumber\":null,\"PostCode\":\"\",\"City\":\"\",\"Country\":\"}}}"
This is kind of JSON ... but as a string. Pay attention to the first and final double quotes and, of course, to all slashes.
I am currently resolving this by String.Replacing a backslash and a first and final quote. After that I can take it apart.
mystring.Replace("\\", "");
However, what if one of the attributes has a backslash as a value? For example:
\"SecondAttribute\":\"My Super Back Slash: \\ . That was it.\"
In this case, I accidentally delete the backslash, which should be there in the value.
Does anyone have a bright idea on how to parse this JSON string correctly?
Gonzalioz
source share