第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將 JSON 嵌套對(duì)象數(shù)組反序列化為 C# 對(duì)象

如何將 JSON 嵌套對(duì)象數(shù)組反序列化為 C# 對(duì)象

C#
紫衣仙女 2023-07-09 16:17:21
我被這個(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;

}



查看完整回答
反對(duì) 回復(fù) 2023-07-09
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)