我被這個(gè)問(wèn)題難住了,無(wú)法繼續(xù)。我也不是很有經(jīng)驗(yàn),因此將不勝感激您的幫助。我正在使用返回以下數(shù)據(jù)的 API:{"userdata":[{"IdCustomer":"4","IdShop_group":"1","IdShop":"2","IdGender":"1","IdDefault_group":"3","IdLang":"2","Company":null,"Firstname":"John","Lastname":"Doe","Email":"johndoe@email.com","NumpadPIN":"99999999","Birthday":"1991-12-24","Newsletter":"0","Optin":"0","Active":"1","Date_add":"2019-04-09 07:37:29","Date_upd":"2019-07-17 11:38:25"}]}我使用“json2csharp”設(shè)置了以下課程public class Userdata{ public string IdCustomer { get; set; } public string IdShop_group { get; set; } public string IdShop { get; set; } public string IdGender { get; set; } public string IdDefault_group { get; set; } public string IdLang { get; set; } public object Company { get; set; } public string Firstname { get; set; } public string Lastname { get; set; } public string Email { get; set; } public string Birthday { get; set; } public string Newsletter { get; set; } public string Optin { get; set; } public string Active { get; set; } public string Date_add { get; set; } public string Date_upd { get; set; }} public class User{ public IList<Userdata> userdata { get; set; }}這是我提取數(shù)據(jù)的方法//changed the url for this question var URL = "https://dummyvalue.com"; var request = new HttpRequestMessage(); request.RequestUri = new Uri(URL); request.Method = HttpMethod.Get; request.Headers.Add("Accept", "application/json"); var client = new HttpClient(); HttpResponseMessage response = await client.SendAsync(request); }我的問(wèn)題是如何分配/使用已反序列化的值?我想訪問(wèn)作為類(lèi)對(duì)象詳細(xì)信息的值,例如。var name = userObject.Firstname;var surname = userObject.Lastname;我讀了很多書(shū)并嘗試了不同的方法,但我一定錯(cuò)過(guò)了一些東西..
1 回答

繁華開(kāi)滿天機(jī)
TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
您需要使用 RootObject
var response = JsonConvert.DeserializeObject<RootObject>(json);
foreach(var userObject in response.userdata)
{
//use here userObject.Firstname;
}
- 1 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報(bào)
0/150
提交
取消