Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to convert this array (API Response) to list:

API Result:
[{"NUMBER":"000000","TEMPLATE":"testing_messages","ATTACHMENT":null,"STATUS":"1","IP_ADDRESS":"196.00.3.234","TIMESTAMP":"1636630840"},
{"NUMBER":"000000","TEMPLATE":"testing_messages","ATTACHMENT":null,"STATUS":"1","IP_ADDRESS":"196.333.3.234","TIMESTAMP":"1636630873"},
{"NUMBER":"000000","TEMPLATE":"testing_messages","ATTACHMENT":null,"STATUS":"1","IP_ADDRESS":"196.202.3.234","TIMESTAMP":"1636631114"},
{"NUMBER":"000000","TEMPLATE":"testing messages","ATTACHMENT":null,"STATUS":"1","IP_ADDRESS":"196.202.3.234","TIMESTAMP":"1636631184"},{"NUMBER":"00000","TEMPLATE":"testing","ATTACHMENT":null,"STATUS":"1","IP_ADDRESS":"196.45.3.234","TIMESTAMP":"1636631222"}]


What I have tried:

i create this class but i don't know how to fetch the result

public partial class CLS_deleveryReport
       {

           public int ID { get; set; }
           public string NUMBER { get; set; }
           public string TEMPLATE { get; set; }
           public string ATTACHMENT { get; set; }
           public string IP_ADDRESS { get; set; }
           public int STATUS { get; set; }
           public DateTime ExpiredDate { get; set; }
           public string STATUS_String { get; set; }
       }
Posted
Updated 12-Nov-21 6:21am
v2
Comments
BillWoodruff 11-Nov-21 9:32am    
A key factor in determining the complexity of the code you'll need to write is how reliable the data is; for each field, like "ip address," will you need to write validation code (or use a RegEx) to check it ?
Golden Basim 11-Nov-21 9:34am    
there are any method to extract the data of fields as it without validations?
BillWoodruff 11-Nov-21 17:15pm    
what does "extract" mean ? break each record into a series of strings ? or, create instances of a strongly typed structure ?

This appears to be a JSON file, so you just use a JSON library, like Newtonsofts[^], and deserialize the data into an array of your class.
 
Share this answer
 
// Define The Model Class as like the following

public class ClsDeliveryReport
{
    public string NUMBER { get; set; }
    public string TEMPLATE { get; set; }
    public object ATTACHMENT { get; set; }
    public string STATUS { get; set; }
    public string IP_ADDRESS { get; set; }
    public string TIMESTAMP { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        string response = ""; // assign the value to response

// Using the Newtonsoft.Json library Can Deserialize the array string to object as follows.
        List<ClsDeliveryReport> reportList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsDeliveryReport>>(response);
    }
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900