Time for action – JSON encoding and decoding
Let's create a simple model: a 3D line. Here we will be focusing on how we do JSON encoding and decoding. Follow the given steps:
- Go to your Internet browser and open the interactive JavaScript console. Use the following table for assistance:
Web browser
Menu option
Shortcut keys (PC / Mac)
Firefox
Tools | Web Developer | Web Console
Ctrl + Shift + K / Command + Alt + K
Safari
Develop | Show Web Inspector
Ctrl + Shift + C / Command + Alt + C
Chrome
Tools | JavaScript Console
Ctrl + Shift + J / Command + Alt + J
- Create a JSON object by typing:
var model = {"vertices":[0,0,0,1,1,1], "indices":[0,1]};
- Verify that the
model
is an object by writing:typeof(model)
- Now, let's print the
Get WebGL Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.