Help making tutorial apps

JSON.parse() is a standard library function so you can look it up but essentially you give it some text that is in JSON format and it returns a JavaScript object equivalent to that structured text (ie with the same members and values).

So for example, a structure/object expressed as text in JSON format such as:

{
   body: "foo",
   metadata: "bar"
}

Pass that to JSON.parse() and it would return an object with members “body” that has value “foo”, and “metadata” that has value “bar”.

var mything = JSON.parse(‘{
body: “foo”,
metadata: “bar”
}’):

returns an object so you do:

alert(mything.body);

And it would display a message box with the text “foo”.

Hope that helps.

EDIT:

Does one prepare code assuming they know what the response will be?

One tests for all possible responses and handles then accordingly. If you look at my code you’ll see this.

2 Likes