Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my JSON

{"HEADER":{"APPLICATION-ID":"","RESPONSE-TYPE":"ACKNOWLEDGEMENT","CUST-ID":"","REQUEST-RECEIVED-TIME":"29122017 16:12:10"},"ERRORS":[{"DESCRIPTION":"User Authentication failed. Check username/ password/ Institution Id / Aggregator Id / IP Address of user and retry.","CODE":"INVALID"}],"STATUS":"ERROR"}


What I have tried:

        WebResponse webResponse = request.GetResponse();
        using (Stream webStream = webResponse.GetResponseStream())
        {
            if (webStream != null)
            {
                using (StreamReader responseReader = new StreamReader(webStream))
                {
                    string response = responseReader.ReadToEnd();


                    JObject o = JObject.Parse(response);
                    Response.Write(o.ToString());
}}}
Posted
Updated 1-Jan-18 21:24pm
v2

I know that I am late to answer, but the following article will give your the tools and code to do this and more:

Working with JSON in C# & VB[^]
 
Share this answer
 
//Add this class into your project

public class HEADER
{
    public string APPLICATION-ID { get; set; }
    public string RESPONSE-TYPE { get; set; }
    public string CUST-ID { get; set; }
    public string REQUEST-RECEIVED-TIME { get; set; }
}

public class ERROR
{
    public string DESCRIPTION { get; set; }
    public string CODE { get; set; }
}

public class JsonObject
{
    public HEADER HEADER { get; set; }
    public List<ERROR> ERRORS { get; set; }
    public string STATUS { get; set; }
}


WebResponse webResponse = request.GetResponse();
     using (Stream webStream = webResponse.GetResponseStream())
     {
         if (webStream != null)
         {
             using (StreamReader responseReader = new StreamReader(webStream))
             {
                 string response = responseReader.ReadToEnd();
                JObject jal =response  as JObject;
                JsonObject Obj= jal.ToObject<JsonObject>();
                // Here You can handle json object values
             }
          }
      }
 
Share this answer
 
v3
Comments
Vikram Singh Rathaur 29-Dec-17 7:35am    
can you pls complete the solution , i am having problem in reading values
F-ES Sitecore 29-Dec-17 9:49am    
They should be in the "Obj" variable which is type JsonObject so should be things like Obj.STATUS etc.
Vikram Singh Rathaur 30-Dec-17 0:09am    
How to read HEADER & ERROR elememt
Vikram Singh Rathaur 30-Dec-17 1:36am    
i am facing problem in reading value from HEADER Class. pls help me urgent
Vikram Singh Rathaur 30-Dec-17 2:15am    
i have done. thanks.

i was facing problem due to property name dash "RESPONSE-TYPE" so changed it with "RESPONSE_TYPE"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900