0
0
Unityframework~10 mins

JSON serialization in Unity - Interactive Code Practice

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

Complete the code to convert an object to a JSON string using Unity's JsonUtility.

Unity
string json = JsonUtility.[1](playerData);
Drag options to blanks, or click blank then click option'
ASerialize
BFromJson
CToJson
DParse
Attempts:
3 left
💡 Hint
Common Mistakes
Using FromJson instead of ToJson
Trying to use Serialize which is not a JsonUtility method
2fill in blank
medium

Complete the code to convert a JSON string back to an object of type PlayerData.

Unity
PlayerData player = JsonUtility.[1]<PlayerData>(jsonString);
Drag options to blanks, or click blank then click option'
AFromJson
BParse
CDeserialize
DToJson
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToJson instead of FromJson
Trying to use Deserialize which is not a JsonUtility method
3fill in blank
hard

Fix the error in the code to correctly deserialize a JSON string into a PlayerData object.

Unity
PlayerData player = JsonUtility.[1](jsonString);
Drag options to blanks, or click blank then click option'
AFromJson<PlayerData>
BParse
CFromJson
DToJson
Attempts:
3 left
💡 Hint
Common Mistakes
Calling FromJson without specifying the type
Using ToJson instead of FromJson
4fill in blank
hard

Fill both blanks to create a JSON string from a PlayerData object and then parse it back.

Unity
string json = JsonUtility.[1](player);
PlayerData newPlayer = JsonUtility.[2]<PlayerData>(json);
Drag options to blanks, or click blank then click option'
AToJson
BFromJson
CParse
DSerialize
Attempts:
3 left
💡 Hint
Common Mistakes
Using Parse or Serialize which are not JsonUtility methods
Mixing up ToJson and FromJson order
5fill in blank
hard

Fill all three blanks to serialize a PlayerData object with pretty print enabled and then deserialize it.

Unity
string json = JsonUtility.[1](player, [2]);
PlayerData loadedPlayer = JsonUtility.[3]<PlayerData>(json);
Drag options to blanks, or click blank then click option'
AToJson
Btrue
CFromJson
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Passing false instead of true for pretty print
Using Parse instead of FromJson