Hi Guys,
I was working on a project and I found a really difficult thing to read values of any json object.
Below is the code for the same, this code can extract any json object
Dictionary<string, string> jdata = new Dictionary<string, string>();
JsonTextReader reader = new JsonTextReader(new StringReader(response.Content));
string p = "", v = "";
while (reader.Read())
{
//Here this 2 represents the nested level of your json.
//ex. {"validated":{"token":"xxxxxx","level":"x"}}
if (reader.Depth == 2)
{
if (reader.TokenType == JsonToken.PropertyName)
{
p = reader.Value.ToString();
}
if (reader.TokenType == JsonToken.String)
{
v = reader.Value.ToString();
}
if (p!="" && v != "")
{
jdata.Add(p, v);
p = "";
v = "";
}
}
}
Hope it help you guys
I was working on a project and I found a really difficult thing to read values of any json object.
Below is the code for the same, this code can extract any json object
Dictionary<string, string> jdata = new Dictionary<string, string>();
JsonTextReader reader = new JsonTextReader(new StringReader(response.Content));
string p = "", v = "";
while (reader.Read())
{
//Here this 2 represents the nested level of your json.
//ex. {"validated":{"token":"xxxxxx","level":"x"}}
if (reader.Depth == 2)
{
if (reader.TokenType == JsonToken.PropertyName)
{
p = reader.Value.ToString();
}
if (reader.TokenType == JsonToken.String)
{
v = reader.Value.ToString();
}
if (p!="" && v != "")
{
jdata.Add(p, v);
p = "";
v = "";
}
}
}
Hope it help you guys