我正在研究一個項目,我想要反序列化 JSON數組。我已經嘗試過,但沒有得到如何解析它。使用Newtonsoft解析JSON數組
JSON數組:
{"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"}]}
下面是我從WebService獲取JSON:
我怎樣努力:
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; }
}
什麼是錯誤? –
我想在字符串中的值,即時通訊新,我不知道如何從json數組中獲取這些值。 –
@DhavalPatel感謝您的回覆,但我如何從''「lec_no」:「FA10-BCS-40」,「reg_no」:「2」,「std_status」獲得這些值FA10-BCS-40,2,A: 「A」' –