Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In my C# program I have a JSON file directory that i'veserialized and deserialized into a list from where I'm ableto access variables from the

In my C# program I have a JSON file directory that i'veserialized and deserialized into a list from where I'm ableto access variables from the list and print them out to theconsole but what i'm struggling with is, how to use a for loop todisplay one JSON file at a time so I can ask the user to rate onemovie at a time.

// This program read from a json file to retrive the year andtitle of some movies
// prompting the user to rate them and saving the data back to thejson file.

using System;
using System.Collections.Generic; // for lists
using System.IO; // used for File.ReadAllText
using System.Text.Json;

namespace ConsoleAssignment4
{
class Program
{
static void Main(string[] args)
{
multipleJson();
}

static void multipleJson()
{
string jsonDirectory ="JSON-Movies";

string[] jsonFiles=System.IO.Directory.GetFiles(jsonDirectory); //used for loop whenopening json files
//Console.WriteLine(jsonFiles[2]);

ListMoviesList = new List { };

Movies oneMovies = newMovies();

string jsonData ="";

//loop read files oneby one and copies all the data into the list
foreach(var jsonFile injsonFiles)
{
jsonData =File.ReadAllText(jsonFile); // extracts all text from json andsaves them to a string

oneMovies =JsonSerializer.Deserialize(jsonData);
MoviesList.Add(oneMovies);

}

// print all themovies
Console.WriteLine("themovies are");
foreach (var aMovies inMoviesList)
{
Console.WriteLine(aMovies.title + " (" + aMovies.year + ")");
}


// go through the listone by one change the score
// use a for statement toprint the movies one at a time changing the variables as you go


// print it to theoriginal json
}
}

class Movies
{
public string id { get; set; }
public string title { get; set; }
public string year { get; set; }
public string runtime { get; set;}
public string genre { get; set; }
public string rating { get; set;}
}
}

Note so far I'm able to display the movies title, and year butit displays all of the movies at ounce I',m trying to display oneat a time so I can then ask the user for a rating

Step by Step Solution

3.38 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

To display one movie at a time you can use a for loop to iterate through the elements of the MoviesL... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Prove the combinatorial identity?

Answered: 1 week ago