Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

How To Create Or Get Values From Array Object Using JSON in Javascript?

Rendyon | 3:36 AM | 0 comments

Today, i am going to  tell  how to use array Object Using JSON in Javascript. In below example, an object (JSONObject) is created containing two members java and json. First member java, which  contains an array containing two objects, each containing name and  price members. Second member json, which contains an array containing two objects, each containing name and  price members.

Example:
var JSONObject = {
"java": [
{"name": "learn java", "price": 500},
{"name": "easy java", "price":400}
],

"json":[
{"name": "learn javaScript", "price": 300},
{"name": "easy javaScript", "price":200}
]
};
java Members can be retrieved using dot or subscript operators easily.
JSONObject.java[0].name       // output: learn java
JSONObject.java[0].price       // output: 500

JSONObject.java[1].name       // output: easy java
JSONObject.java[1].price       // output: 400

json Members can be retrieved using dot or subscript operators easily.
JSONObject.json[0].name       // output: learn javaScript
JSONObject.json[0].price       // output: 300

JSONObject.json[1].name       // output: easy javaScript
JSONObject.json[1].price       // output: 200

Check running example here:
http://jsfiddle.net/jeetu_verma11/7D8jz/

How To Create Or Get Values Of JSON Object in JavaScript Example?

Rendyon | 11:34 PM | 0 comments
JavaScript is a general purpose programming language that was introduced as the page scripting language for Netscape Navigator. JSON or JavaScript Object Notation  is a subset of the object literal notation of JavaScript. It has become a popular for defining structured data using JavaScript.

JSON supports following values:
    number (integer or floating point)
    string
    boolean
    array
    object
    null
Here is the example for creating JSON object :
var JsonObj={
'langName' : "javascript",
'notation' : "JSON",
'price': 500,
'date': "28 July 2013",
'easy' : "true"
};
JSON attributes is accessed by using '.' (dot) Operator easily.
So if we want to access langName attribute, we can access like this:

JsonObj.langName   here JsonObj (JSON object name) and langName is object attribute.
output: javascript

Similarly for price attribute:
JsonObj.price
output: 500

Check running example here:
http://jsfiddle.net/jeetu_verma11/A7t2m/9/
 
Copyright © 2011. Find Updates - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger