edit-article
Home
Up
Delete
Article Name:
Article Description:
defining an 'object' using javascript object notation(json)] UPDATE ARTICLE TO : change to encoding/decoding objects using the JSON objects methods of ...
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">object - json</h1> <h2 style="text-align: left;"><br />[what]</h2> <ol> <li><strong>] json stands for javascript object notation,</strong></li> <ol> <li>] with json you can create js objects by simply defining them, similar to specify an <span style="text-decoration: underline;">object literal</span></li> <li>] with json you can pass objects to ...</li> </ol> <li><strong>] you create an object by simply using the kewyord var to create the name and then assigning a set of empty braces {} to that name;</strong></li> <ol> <li>] var myObject = {};</li> <li>] the example above wont do much(or anything) at this point but it is a valid js object</li> </ol> <li><strong>] the example below to see what the previous object looks like declared using json</strong></li> <ol> <li>] did you notice its exactly the same as the object literal declaration of an object</li> </ol> <li><strong>] in js an "object" consists of name value pairs, names and values are separted by a colon : and </strong></li> <ol> <li>] so if we wanted our object to have an id property, we would give it a name value pair of name=id and value=whatever value that we wanted to assign to the id property</li> <li>] SO for exampled if we wanted name - id , with an id value of 3</li> <li>] var myObject = {id:3}</li> </ol> <li><strong>] JSON objects !=== the JSON object</strong></li> <ol> <li>] the JSON object - has methods for parsing JSON objects (turning json into objects) and stringify (turning json objects into strings )</li> </ol></ol> <h2>[why]</h2> <ol> <li>] JSON is a data interchange format - typically used to pass application data between .... and ....</li> </ol> <h2>[when]</h2> <ol> <li>] var myCar = JSON.parse(myCarInJson);</li> <li>] var myCarToJson = JSON.stringify(myCar);</li> </ol> <h2>[example]</h2> <p>var myObject = {<br />"name":"dons object",<br />"function":"getName(){alert(myObject.name);}"<br />}</p> <h2>[how-to]</h2> <ol> <li>] if your object has more then 1 property(most all do),<ol> <li>] seperate ,each name/value pair with a comma in your object declaration</li> </ol></li> <li>] SO for example, lets add another property to our object named "L1" and assign it the value of "subjects"</li> <ol> <li>var myObject = {id:3,L1:"subjects"}</li> </ol> <li>] if your object has even more properties, just keep on seperating each additional name/value pair with commas</li> <ol> <li>var myObject = {id:3,L1:"subjects",L2:"objects",L3:"systems"}</li> </ol></ol> <h2>[reference]</h2> <ol> <li>] (id=2736) create art task</li> <li>] <a href="http://stackoverflow.com/questions/12440350/create-a-json-object-in-javascript" target="_blank">http://stackoverflow.com/questions/12440350/create-a-json-object-in-javascript</a> </li> <li>] <a href="http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/">http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/</a> </li> </ol> <p> </p> <hr /> <p>003 // OBJECT - JSON</p> <p>var app = {</p> <p>name: "subjects",</p> <p>qryL1: "../qry/Select-Libraries-a.cshtml/", <br />L1: "Library",<br />id : $("#id_article").text(),<br />qryMove: "../qry/updateArticle/",<br />Destination: "-",<br />qryCopy:"../qry/copy_records/", <br />To: $("#parent_id2").val()<br />};</p>