0
 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',
                       }];
1
  • Can you show your code where you've converted to a list? Commented Jan 30, 2018 at 11:07

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.