Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
C Sharp (C#) - File IO
What is wrong with this code?
using System.Text.Json;

var json = "{ 'Name': 'John' }";
var person = JsonSerializer.Deserialize(json);
APerson class must be static to deserialize
BDeserialize method cannot parse JSON with Name property
CJSON uses single quotes instead of double quotes
DJsonSerializer requires JsonDocument input
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON string format

    JSON standard requires double quotes for property names and string values, not single quotes.
  2. Step 2: Confirm other options are incorrect

    Deserialize can parse Name property if JSON is valid. Person class does not need to be static. JsonSerializer accepts string input.
  3. Final Answer:

    JSON uses single quotes instead of double quotes -> Option C
  4. Quick Check:

    JSON strings must use double quotes [OK]
Quick Trick: Use double quotes in JSON strings for valid parsing [OK]
Common Mistakes:
MISTAKES
  • Using single quotes in JSON strings
  • Assuming class must be static
  • Thinking JsonSerializer needs JsonDocument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes