Jump to content
Howdy_McGee

AJAX and JSON

Recommended Posts

So I can't for the life of me understand JSON. I've looked through numerous links but nothing. If I have a Database and all I want to pull is:title => fight clubtype = > moviegenre => actionhow do I print that out to an HTML document using JSON. I don't get it. I think it puts it in an array but how does it get there? Do I just print it out like I would a normal javascript array? If this isn't quite the right place to post this I apologize but there wasn't an AJAX section.

Share this post


Link to post
Share on other sites

JSON is unrelated to AJAX.JSON is just a quick way to write objects and arrays.

// Normal Javascriptvar a = new Object();a.property1 = 1;a.property2 = 2;// The same thing in JSONvar a = {  "property1": 1,  "property2": 2}

// Normal Javascriptvar b = new Array();b[0] = "value";b[1] = "value";// The same thing in JSONvar b = [ "value", "value" ];

Share this post


Link to post
Share on other sites
So then to print value of the array using JSON I would do the same as javascript? document.write(b[0])?
Yes, I think so. To me, it seems that JSON or JS means no difference to me. I tend to use the JSON way to create Arrays but sometimes turn to the JS Array way.In your example, I can't think of another way in JS that you can print out an index value. That might be the only way, to the best I know of JS.
// No matter how you sort out your arrays// Normal Javascriptvar b = new Array();b[0] = "value";b[1] = "value";// The same thing in JSONvar b = [ "value", "value" ];// You still need to refer back to an index and this is the only way to refer to an index (you don't have much choice about b[0])document.write(b[0]); // the same as yours

Maybe ya can just go ahead into whatever makes out the effects.May not be that necessary to tell them apart before ya can use JS.

Share this post


Link to post
Share on other sites

b[0] is a reference to your value, yes. But for goodness' sake get out of the habit of using document.write!FWIW, JSON, means JavaScript Object Notation. It works in JavaScript because it is JavaScript, not something different.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...