Tier 2
Series 106
106D: The JSON Carrier
"You cannot save a Class directly to PlayerPrefs. You must convert it to text first. An Engineer uses **JSON (JavaScript Object Notation)** to turn a C# object into a String, and back again."
The Concept: JsonUtility
The translator between Code and Text.
* **ToJSON:** Class -> String (`{"level": 5, "gold": 10}`).
* **FromJSON:** String -> Class.
* **Storage:** The entire String is saved under one Key.
* **ToJSON:** Class -> String (`{"level": 5, "gold": 10}`).
* **FromJSON:** String -> Class.
* **Storage:** The entire String is saved under one Key.
Red Flag Detected
The AI Trap: "The Binary Blob"
You ask the AI: "Save the class to a file."
// AI-Generated Code: BinaryFormatter // Audit Fail: BinaryFormatter is obsolete and dangerous (Security Risk). BinaryFormatter bf = new BinaryFormatter();
This is "Security Deprecation." BinaryFormatter is unreadable and insecure. Modern games use JSON.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Engineer's Correction
Corrective Protocol
// Corrected: Text Format string json = JsonUtility.ToJson(myData); File.WriteAllText(path, json);
Your Pilot Command
> Direct the AI to use JSON serialization for saving and loading player progress.