I'm struggling to parse JSON in c# that is structured like the example below. The code snippet I have been using is somewhat functional, but it lacks stability.
(I'm also looking for guidance on how to parse JSON in Javascript, which is another task on my plate.)
Take a look at the JSON format I am working with:
{"72": { "Rejected": true }, "271": { "PreApproved": true}}
Here's a snippet of the code I've been working with:
List<SSKChanges> lstSSK = new List<SSKChanges>();
string sskSource = "";
string sskStatus = "";
bool sskStatusBool = false;
int i = 0;
int iList = 0;
JsonTextReader reader = new JsonTextReader(new StringReader(jsonExample));
while (reader.Read())
{
if (reader.Value != null)
{
if (i == 0)
{
int n;
bool isNumeric = int.TryParse(reader.Value.ToString(), out n);
if (isNumeric)
{
sskSource = reader.Value.ToString();
i = 1;
}
else
{
sskStatus = reader.Value.ToString();
i = 2;
}
}
else if (i == 1)
{
sskStatus = reader.Value.ToString();
i = 2;
}
else
{
sskStatusBool = (bool)reader.Value;
i = 0;
sskSource = "";
sskStatus = "";
sskStatusBool = false;
}
}
}