Jump to content

AJAX and JSON


Howdy_McGee

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.

Link to comment
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" ];

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...