0
0
C Sharp (C#)programming~10 mins

Working with JSON files in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a JSON file into a string.

C Sharp (C#)
string jsonString = File.[1]("data.json");
Drag options to blanks, or click blank then click option'
AWriteAllLines
BWriteAllText
CReadAllLines
DReadAllText
Attempts:
3 left
💡 Hint
Common Mistakes
Using WriteAllText instead of ReadAllText will overwrite the file.
ReadAllLines returns a string array, not a single string.
2fill in blank
medium

Complete the code to deserialize JSON string into an object of type Person.

C Sharp (C#)
Person person = JsonSerializer.[1]<Person>(jsonString);
Drag options to blanks, or click blank then click option'
AParse
BDeserialize
CSerialize
DConvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using Serialize instead of Deserialize will convert an object to JSON, not the other way.
Parse is not a method in JsonSerializer.
3fill in blank
hard

Fix the error in the code to serialize an object to JSON string.

C Sharp (C#)
string jsonString = JsonSerializer.[1](person);
Drag options to blanks, or click blank then click option'
ADeserialize
BParse
CSerialize
DConvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using Deserialize will cause a compile-time error because it expects a JSON string input.
Parse and Convert are not methods of JsonSerializer.
4fill in blank
hard

Fill both blanks to write a JSON string to a file asynchronously.

C Sharp (C#)
await File.[1]Async("output.json", jsonString[2]);
Drag options to blanks, or click blank then click option'
AWriteAllText
BReadAllText
CWriteAllLines
D, CancellationToken.None
Attempts:
3 left
💡 Hint
Common Mistakes
Using ReadAllTextAsync instead of WriteAllTextAsync will read instead of write.
Omitting the cancellation token parameter may cause errors in some contexts.
5fill in blank
hard

Fill all three blanks to create a dictionary from JSON and filter keys with length > 3.

C Sharp (C#)
var filtered = jsonDict.Where(kv => kv.Key.[1] > 3).ToDictionary(kv => kv.[2], kv => kv.[3]);
Drag options to blanks, or click blank then click option'
ALength
BKey
CValue
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for string length.
Swapping Key and Value in ToDictionary parameters.