Abdifatah Abdilahi
Abdifatah Abdilahi

Reputation: 59

How to query JSON data from list using C# UWP

 string Categoriesjson = @"[
                       {
                        'cat_id' : 1,
                         'name': 'HTML',
                         'desc': 'WebDesign',
                         'img': 'Assets/sawirada/html-flat.png',
                       }];

I have this JSON data i Converted to a list, I Want to Pass the Category id to a courses page and list the courses that match this category Id using LINQ.

 string Coursesjson = @"[
                       {
                         'id'  : 1,
                         'cat_id' : '2',
                         'name': 'Learn HTML',
                         'date': '2017-10-19',
                         'img': 'Assets/sawirada/phpmysql.jpg',
                       }];

Upvotes: 0

Views: 89

Answers (1)

Handsome Greg
Handsome Greg

Reputation: 325

Deserialize the Coursejson to a list, and use LINQ to get the matching courses:

var passedCatId = 1;
List<Course> allCourses = JsonConvert.DeserializeObject<List<Course>>(Coursejson);

List<Course>filteredCourses = allCourses.Where(c => c.cat_id == passedCatId).ToList();

Upvotes: 1

Related Questions