Javascript - Working with API-like Data
Code Life
By Pierre Marsaa
What a Server Actually Sends
When your game asks a server for a player's profile, the server answers with a single JSON string that packs everything together: a status, the trainer's info, and the full team of Codémon.
Before you do anything with it, that response is still just one long string:
↗️
Loading editor...
↶
↷
Working with a server response always follows the same three steps:
1.
Parse the JSON string into a real JavaScript object using JSON.parse().
2.
Check that the response succeeded (for example, data.status === "ok").
3.
Navigate into the nested objects and arrays to read what you need.
↗️
Loading editor...
↶
↷
Verify