In c#, I'm trying to parse JSON that is in the following format. I've only been able to come close using the example code below, but it is very unstable.
(I'm also not sure how to parse in Javascript, which I also need to do.)
JSON example:
{"72": { "Rejected": true }, "271": { "PreApproved": true}}
Code example:
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;
}
}
}