Amazon Ad

Tuesday, 13 June 2017

How to read any json from API in C# Dictionary class object?

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

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...