article

object - json


[what]

  1. ] json stands for javascript object notation,
    1. ] with json you can create js objects by simply defining them, similar to specify an object literal
    2. ] with json you can pass objects to ...
  2. ] 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;
    1. ] var myObject = {};
    2. ] the example above wont do much(or anything) at this point but it is a valid js object
  3. ] the example below to see what the previous object looks like declared using json
    1. ] did you notice its exactly the same as the object literal declaration of an object
  4. ] in js an "object" consists of name value pairs, names and values are separted by a colon : and  
    1. ] 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
    2. ] SO for exampled if we wanted name - id , with an id value of 3
    3. ] var myObject = {id:3}
  5. ] JSON objects !=== the JSON object
    1. ] the JSON object - has methods for parsing JSON objects (turning json into objects) and stringify (turning json objects into strings )

[why]

  1. ] JSON is a data interchange format - typically used to pass application data between .... and ....

[when]

  1. ] var myCar = JSON.parse(myCarInJson);
  2. ] var myCarToJson = JSON.stringify(myCar);

[example]

var myObject = {
"name":"dons object",
"function":"getName(){alert(myObject.name);}"
}

[how-to]

  1. ] if your object has more then 1 property(most all do),
    1. ] seperate ,each name/value pair with a comma in your object declaration
  2. ] SO for example, lets add another property to our object named "L1" and assign it the value of "subjects"
    1. var myObject = {id:3,L1:"subjects"}
  3. ] if your object has even more properties, just keep on seperating each additional name/value pair with commas
    1. var myObject = {id:3,L1:"subjects",L2:"objects",L3:"systems"}

[reference]

  1. ] (id=2736) create art task
  2. ] http://stackoverflow.com/questions/12440350/create-a-json-object-in-javascript 
  3. ] http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/ 

 


003 // OBJECT - JSON

var app = {

name: "subjects",

qryL1: "../qry/Select-Libraries-a.cshtml/", 
L1: "Library",
id : $("#id_article").text(),
qryMove: "../qry/updateArticle/",
Destination: "-",
qryCopy:"../qry/copy_records/",
To: $("#parent_id2").val()
};

Details Photos Edit more

Details

ID: 1680

NAME: 003-CREATING-objects-from-JSON

DESCRIPTION: defining an 'object' using javascript object notation(json)] UPDATE ARTICLE TO : change to encoding/decoding objects using the JSON objects methods of ...

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and