如何在xamarin android中从json响应中获取价值?(android应用中的用户登录目的)

问题描述 投票:0回答:1

C#代码:

var handler = new HttpClientHandler();

HttpClient client = new HttpClient(handler);

string result = await client.GetStringAsync(url);

Console.WriteLine(result);

Json respose(result):

{"accountstab":[{"LoginType":"r","RepId":3368,"RepName":"Aachi's M","RepUName":"aachis","RepPwd":"aachis123","WhlId":null,"RepLocalId":null,"WhoName":"Aachi's M","WhoTin":"32661034","WhoEmail":"[email protected]"},
{"LoginType":"r","RepId":3335,"RepName":"AL-NAJA M","RepUName":"alnaja","RepPwd":"chemmad","WhlId":null,"RepLocalId":null,"WhoName":"AL-NAJA","WhoTin":"7222075","WhoEmail":"[email protected]"}]}

模型类:

 public class RootObject

    {
        public List<Accountstab> accountstab { get; set; }
    }
    public class Accountstab
    {
        public string LoginType { get; set; }
        public int RepId { get; set; }
        public string RepName { get; set; }
        public string RepUName { get; set; }
        public string RepPwd { get; set; }
        public int? WhlId { get; set; }
        public int? RepLocalId { get; set; }
        public string WhoName { get; set; }
        public string WhoTin { get; set; }
        public string WhoEmail { get; set; }
    }
c# json xamarin.android
1个回答
0
投票
using Newtonsoft.Json;
// ... 
RootObject json = JsonConvert.DeserializeObject<RootObject>(result);
© www.soinside.com 2019 - 2024. All rights reserved.