0
    public class walletcustinfo
    {
        public int ID { get; set; }
        public string ATTRIBUTECODE { get; set; }
        public string ATTRIBUTENAME { get; set; }
        public string ATTRIBUTEVALUE { get; set; }
        public int ISMANDATORY { get; set; }
        public int ISUNIQUE { get; set; }
        public int ACCOUNTHOLDERID { get; set; }
    }

    public class Rootwalletinfo
    {
        public string code { get; set; }
        public string description { get; set; }
        public List<walletcustinfo> data { get; set; }
    }

    public Rootwalletinfo GetWalletCustomerInfo(string cnic, string IP)
    {
        Rootwalletinfo _response = new Rootwalletinfo()
        {
            code = "99",
            description = "Transaction Failed"
        };
        try
        {
            string url = "http://99.99.99.99:7777/Wallet-ggg-iurytrr/services/wallet/CustomerInfo/";
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(url);
            client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

            Log.WriteOnboardWalletLogEntry("\n\nInfo", IP, "Getting Response: ");

            HttpResponseMessage response = client.GetAsync(cnic).Result;

            var resp = response.Content.ReadAsStringAsync().Result;

            _response = JsonConvert.DeserializeObject<Rootwalletinfo>(resp);

            return _response;
        }
        catch (Exception e)
        {
            return _response;
        }
    }

Json Response: { "code": "00", "description": "SUCCESS", "data": [ { "ID": 6547362, "ATTRIBUTECODE": "Company Name", "ATTRIBUTENAME": "Company Name", "ATTRIBUTEVALUE": "Jerry", "ISMANDATORY": 0, "ISUNIQUE": 0, "ACCOUNTHOLDERID": 6454647 }, { "ID": 10540617, "ATTRIBUTECODE": "Product Name", "ATTRIBUTENAME": "Product Name", "ATTRIBUTEVALUE": "Pay Level 0", "ISMANDATORY": 0, "ISUNIQUE": 0, "ACCOUNTHOLDERID": 4353647 } ] }

1 Answers1

0

try this code

    var rootWalletInfo = GetWalletCustomerInfo(..);

    var values = rootWalletInfo.Data.Select(d => new {AttributeName= d.Attributename, AttributeValue=d.Attributevalue} );
    
    // or search
    
    var value= rootWalletInfo.Data.Where( i=> i.Attributename=="Company Name")
               .Select(d => d.Attributevalue ).FirstOrDefault(); // Jerry

and to comply with c# name conventions , it is better to use these classes

public partial class RootWalletInfo
    {
        [JsonProperty("code")]
        public string Code { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }

        [JsonProperty("data")]
        public List<WalletCustInfo> data { get; set; }
    }

    public partial class WalletCustInfo
    {
        [JsonProperty("ID")]
        public long Id { get; set; }

        [JsonProperty("ATTRIBUTECODE")]
        public string Attributecode { get; set; }

        [JsonProperty("ATTRIBUTENAME")]
        public string Attributename { get; set; }

        [JsonProperty("ATTRIBUTEVALUE")]
        public string Attributevalue { get; set; }

        [JsonProperty("ISMANDATORY")]
        public long Ismandatory { get; set; }

        [JsonProperty("ISUNIQUE")]
        public long Isunique { get; set; }

        [JsonProperty("ACCOUNTHOLDERID")]
        public long Accountholderid { get; set; }
    }
Serge
  • 40,935
  • 4
  • 18
  • 45