• Complain

Rehan Zaidi [Rehan Zaidi] - JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development

Here you can read online Rehan Zaidi [Rehan Zaidi] - JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Rehan Zaidi [Rehan Zaidi] JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development
  • Book:
    JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2017
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Easily master JavaScript (JS) with this quick guide and develop mobile and desktop applications for SAP Fiori. This book equips ABAP/SAP developers with the essential topics to get started with JS.

The focus of JavaScript Essentials for SAP ABAP Developers is on the parts of the JS language that are useful from the perspective of an ABAP developer. The book starts with a brief intro to HTML, the basics of JS, and how to create and run a simple JS program. It then dives into the details of the language, showing how to make simple programs. It covers loops in detail, mathematical operations, and string and regular expressions in JS, as well as a taste of functions, followed by objects and object-oriented programming in JavaScript. The book provides:

  • Sample code and screenshots to help you fully understand JS
  • A chapter on JS best practices and recommendations
  • Differences and comparisons of the elements and data structures of ABAP and JavaScript to help you quickly master the material

What Youll Learn

  • Create and run a simple JavaScript program
  • Understand loops, operations, and expressions
  • Master the Create and Use functions
  • Use objects and object-oriented programming in JS
  • Apply the best practices of JS programming

Who This Book Is For

SAP programmers and developers, ABAP users and developers, and university students learning ABAP and JavaScript

Rehan Zaidi [Rehan Zaidi]: author's other books


Who wrote JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development? Find out the surname, the name of the author of the book and a list of all author's works by series.

JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make

Rehan Zaidi 2017

Rehan Zaidi , JavaScript Essentials for SAP ABAP Developers , 10.1007/978-1-4842-2220-1_10

10. JavaScript Object Notation (JSON)

Rehan Zaidi 1

(1) Karachi, Pakistan

This chapter introduces the various ways you can use JavaScript Object Notation. It starts with an overview of JSON and then dives into the details of the data types used in JSON. You will then see how the JSON arrays and objects work in JS programs. Finally, you will see two useful methods, parse and stringify , of the JSON object.

JSON: An Overview

JSON is a form of data representation that lets you arrange interchangeable information in an organized manner. JSON is in text form (human-readable) and resides in a file. The usual file extension associated to JSON files is .json.

Note

Apart from JavaScript, JSON may be used for Java, Python, Perl, etc. JSON may be used to exchange data between a browser and a server.

The syntax of JSON is a subset of JavaScript syntax consisting of data having name and value pairs.

The objects are contained in curly brackets, {}, separated by commas, whereas Objects and each name followed by colon (:). Arrays are contained within square brackets, [], and values are separated by commas.

var Employee = { "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }
var Company = { "Employee": [
{ "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" },
{ "name":"John", "empid":4536, "position":"Associate", "city":"Denver" }
] }

Consider the example presented in Listing .

Listing 10-1. JSON Example

var empObj;
empObj = { "name":"Kelvin Desouza", "empId":17924, "designation":"Trainer", "city":"London" };
console.log(empObj.name + " " + empObj.empId);

In this code, you can see the creation of an object with JavaScript using JSON-like syntax. This example declares the variable named empObj , assigns to it some name/value pairs, and then accesses the objects values using dot notation. Only the employee name and ID are specified in the console.log method, so only those two values will be displayed in the web browser console.

The output of Listing .

Figure 10-1 Output JSON Data Types JSON has the following data types - photo 1
Figure 10-1. Output
JSON Data Types

JSON has the following data types:

  • Number: Numbers in JSON cannot appear within quotes, and are usually integer or floating point. For example:

    { "empid": 123 }
  • String: JSON strings are written in double quotes. For example:

    { "empname": "Twinkle" }
  • Boolean: The value may be true or false . For example:

    { "Pass":true }
  • Object: A JSON object can be any set of pairs of values. For example:

    {
    "Employee": { "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }
    }
  • Array: - the values can be grouped in an array. For example:

    {
    "Employee": [ "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" ]
    }
  • Null: These are empty or no values. For example:

    { "value":null }
JSON Objects

The syntax of JSON objects is

var Employee = { "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }

As previously mentioned, the JSON objects are within curly brackets, {}, and contain key-value pairs that are separated by a colon (:). The key in the case of objects is also always a string that is within double quotes. The values pertaining to these keys may be of any data types (such as number, string, array, and so on).

There are two ways to access the object values: using dot (.) notation, like Employee.name , or by placing the value in brackets, like Employee["name"] .

There are three ways to create JSON objects via JS coding:

  • Create an empty object:

    var myEm = {};
  • Create a new object:

    var myEm = new Object();
  • Create a JSON object with key/value pairs:

    var myEm = { "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }

Listing shows a fully working example.

Listing 10-2. JSON Object Example

var product, val;
product = { "prname":"Smart Phone", "price":20000, "company":"Sony", "camera":null };
console.log( "Product name is: " + product["prname"] + " company: " + product["company"] );

This code is the same as code shown in Listing .

Figure 10-2 Output JSON Arrays The values are in the form of array as in - photo 2
Figure 10-2. Output
JSON Arrays

The values are in the form of array as in JavaScript. The values are held in square brackets, [], and array values can be of any data types (number, string, array, object, Boolean, or null).

{
"soldin" : [ "US", "UK" ]
}

To access array values, use an index number like this:

soldin[1];

To better understand this concept, consider Listing .

Listing 10-3. JSON Array Example

var sellingitem;
sellingitem = {
"itemname":"Smart Phone",
"itemprice":20000,
"soldin":[ "US","UK" ]
};
console.log( "Product " + sellingitem.itemname +
" is sold in " + sellingitem.soldin[0] + ' and ' +
sellingitem.soldin[1] );

This example has a variable sellingitem that represents an object, with suitable values assigned to it. Within this object is an array soldin that contains the countries in which the item is sold. The console.log method is used to print the product name and the countries in the console. The output of Listing .

Figure 10-3 Output In this case weve defined a JSON array for a key value - photo 3
Figure 10-3. Output

In this case, weve defined a JSON array for a key value company with different attributes like Sony, Apple, Lenovo, and Samsung. Now, to access this array value, we use an index number with an object. So in this way we can identify a product brand name from a JSON array.

JSON parse Method

The parse method allows you to convert a data stream received in the form of a string (i.e., information in JSON form) into a JS object. To better understand the usage of the method, consider a scenario where you have a string containing name , ID , position, and trainer data pertaining to an employee. The parse method will use this as follows:

var Employee = JSON.parse('{ "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }');

The parse method will take as input the entire JSON represented in string form. The result of this method execution will be returned in the form of an employee object.

The complete code for this example is shown in Listing .

Listing 10-4. JSON parse Method Example

var Employee;
Employee = JSON.parse('{ "name":"Twinkle", "empid":1234, "position":"Trainer", "city":"London" }');
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development»

Look at similar books to JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development»

Discussion, reviews of the book JavaScript Essentials for SAP ABAP Developers: A Guide to Mobile and Desktop Application Development and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.