4

I'm working on a project in which I want to deserialize a JSON Array. I have tried but didn't get how to parse it.

JSON ARRAY:

{"showAttendanceResult":[{"lec_no":"FA10-BCS-40","reg_no":"2","std_status":"A","std_username":"fahidnadeem"},{"lec_no":"FA10-BCS-4","reg_no":"2","std_status":"A","std_username":"muneebamjad"}]}

Here is the JSON which I get from the WebService:

How I Tried:

    string URL = "http://localhost:32319/ServiceEmployeeLogin.svc/getattendance";
    WebRequest wrGETURL;
    wrGETURL = WebRequest.Create(URL + "/" + Server.UrlEncode("24-06-2014"));
    wrGETURL.Method = "POST";
    wrGETURL.ContentType = @"application/json; charset=utf-8";
    HttpWebResponse webresponse = wrGETURL.GetResponse() as HttpWebResponse;

    Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
    // read response stream from response object
    StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);

    // read string from stream data
    strResult = loResponseStream.ReadToEnd();
    // close the stream object
    loResponseStream.Close();
    // close the response object
    webresponse.Close();

    RootObject ro = JsonConvert.DeserializeObject<RootObject>(strResult);

    //what to do now?
    }
}

public class ShowAttendanceResult
{
    public string lec_no { get; set; }
    public string reg_no { get; set; }
    public string std_status { get; set; }
    public string std_username { get; set; }
}

public class RootObject
{
    public List<ShowAttendanceResult> showAttendanceResult { get; set; }
}
3
  • I want the values in string, im new and i dont know how to get these values from json array. Commented Jun 24, 2014 at 13:49
  • @DhavalPatel thanks for your response, but how can i get these values FA10-BCS-40, 2, A from "lec_no":"FA10-BCS-40","reg_no":"2","std_status":"A" Commented Jun 24, 2014 at 13:55
  • see my ans I have posted it Commented Jun 24, 2014 at 13:55

2 Answers 2

3
RootObject ro = JsonConvert.DeserializeObject<RootObject>(strResult);

foreach(var item in ro.showAttendanceResult)
{
    string _name= item.lec_no;
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use something like this:

foreach(var item in ro.showAttendanceResult)
{
    string lec_no = item.lec_no;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.