none
Determine returned rows in HttpClient RRS feed

  • Question

  • Hi,

    In below code, I am getting homepage items using HttpClient..

    Using the same code, how can I check if the return has rows or it's zero?

    var client = new HttpClient();
    client.BaseAddress = new Uri("https://www.domain.com/ws/populate_homepage.php?country=" + Convert.ToString(App.Current.Properties["EitharMemberCountryCode"]));
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage response = await client.GetAsync("https://www.domain.com/ws/populate_homepage.php?country=" + Convert.ToString(App.Current.Properties["EitharMemberCountryCode"]));
                           
    if (response.IsSuccessStatusCode)
    {
        var data = await response.Content.ReadAsStringAsync();
    
        var result = JsonConvert.DeserializeObject<List<EitharStory>>(data);
        ObservableCollection<EitharStory> trends = new ObservableCollection<EitharStory>(result);
        if (THERE_IS_DATA_THEN)
        { ---------- }
        else
        { ---------- }
    }
    

    Thanks,

    Jassim




    • Edited by Jassim Rahma Thursday, December 21, 2017 9:40 PM
    Thursday, December 21, 2017 9:39 PM

All replies

  • Have you tried ‘if(trends.Count != 0)…’?

    Friday, December 22, 2017 5:58 AM
  • Hi Jassim Rahma,

    Thank you for posting here.

    According to your description, I try to test your code. It is not a complete project, I could not reproduce what you want to get.

    I assume that the data you get from the response if json file and you want to deserialize the json file. Like the code below, it deserliaze a json file and then you could output the value according to the key.

    I make a list json file to reproduce. 

     static void Main(string[] args)
            {
     
    string json = @"['Starcraft','Halo','Legend of Zelda']";
    
                List<string> videogames = JsonConvert.DeserializeObject<List<string>>(json);
    
                ObservableCollection<Rootobject> trends = new ObservableCollection<Rootobject>(videogames);//here is a complier error, ignore it.
    
                if () //check 
                {
    
                }
                Console.WriteLine(string.Join(", ", videogames.ToArray()));
                // Starcraft, Halo, Legend of Zelda
                Console.ReadKey();
            }
    
        }
    
        public class Rootobject
        {
            public string[] Property1 { get; set; }
        }
    

    >>Using the same code, how can I check if the return has rows or it's zero?

    What does the return has rows? Or it's zero? Does the return means trends? What does the rows mean? Count? If you want to check the count of the trends collection, you could try the way Virorel provided.

    If you want to check something else, please provide more details. The json file you used to deserliaze would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 22, 2017 7:57 AM
    Moderator
  • Hi Jassim Rahma,

    Any update?

    If your question has been solved, please mark the useful reply as answer to close the thread. This will make answer searching easier in the forum and be beneficial to community members.

    If you have something else about this issue, please feel free to contact us.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, December 27, 2017 5:39 AM
    Moderator