1 / 25

Consuming Java Script Object Notation (JSON) feeds

Consuming Java Script Object Notation (JSON) feeds. What is JSON? . JSON stands for J ava S cript  O bject  N otation is syntax for storing and exchanging text information Much like XML is smaller than XML, and faster and easier to parse.

Download Presentation

Consuming Java Script Object Notation (JSON) feeds

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Consuming Java Script Object Notation (JSON) feeds

  2. What is JSON? • JSON • stands for JavaScript Object Notation • is syntax for storing and exchanging text information • Much like XML • is smaller than XML, and faster and easier to parse {"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }]}

  3. Contrasting XML to JSON • Similarities: • both are • Plain-text • Self-describing (human readable) • Hierarchical (values nested within values) • Differences: • JSON • Uses no end tags • Is shorter • Quicker to read and write • Uses arrays

  4. JSON syntax • JSON data • written as name/value pairs • Separated by commas (,) • JSON objects • Enclosed in curly brackets ({}) • JSON arrays • Delineated by square brackets ([]) "firstName" : "John" { "firstName":"John" , "lastName":"Doe" } {"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }]}

  5. String Class

  6. String constructors • No-argument constructor creates a • String that contains no characters • (i.e., the empty string, which can also be represented as "") and • has a length of 0. • Constructor that takes a • String object • copies the argument into the new String. • char array creates • a String containing a copy of the characters in the array. • char array and 2 integers creates • a String containing the specified portion of the array.

  7. Example

  8. String length, charAt, and getChars methods • String method • length • determines the number of characters in a string. • charAt • returns the character at a specific position in the String. • getChars • copies the characters of a String into a character array. • The 1st argument is the starting index in the source String. • The 2nd argument is the index that is one past the last character in source String. • The 3rd argument is the character array into which the characters are to be copied. • The 4th argument is the starting index where the copied characters are placed in the target character array.

  9. Example

  10. Comparing Strings • Strings are compared using one of the methods below • boolean equals • boolean equalsIgnoreCase • int compareTo • boolean regionMatches

  11. Comparing Strings • Strings are compared using one of the methods below • boolean equals • returns true if the contents of the objects are equal and false otherwise • boolean equalsIgnoreCase • ignores the case when performing comparison • int compareTo • returns • 0 if contents are equal • A negative number if string invoking compareTo < argument • A positive number if string invoking compareTo > argument • boolean regionMatches • compares portions of two strings for equality

  12. String startsWith and endsWith

  13. Locating characters and substrings in Strings • The following methods can be used: • int indexOf • 1st version locates the 1st occurrence of a char in a String returning • its index, or -1 otherwise • 2nd version takes two arguments, a char and an int parameters • the int represents the starting index at which search begins • int lastIndexOf • 1st version locates the last occurrence of a char in a String returning • its index, or -1 otherwise • 2nd version takes two int arguments • the 1stint is an integer representation of the character • the 2nd represents an index from which searching begins

  14. Extracting substring from Strings

  15. Concatenating strings

  16. Miscellaneous String methods • replace • returns a new String object in which • every occurrence of the first argument is replaced with the second. • toUpperCase • generates a new String with uppercase letters. • toLowerCase • returns a new String object with lowercase letters. • trim generates a new String object that • removes all whitespace characters that • appear at the beginning or end of the String on which trim operates. • Method toCharArray creates a new character array • containing a copy of the characters in the String.

  17. StringBuilder

  18. StringBuilder • Class StringBuilder is used to • create and manipulate dynamic string information. • Every StringBuilder is capable of • storing a number of characters specified by its capacity. • If the capacity of a StringBuilder is exceeded, • the capacity expands to accommodate • the additional characters.

  19. StringBuilder constructors • No-argument constructor creates a • StringBuilder with no characters in it and • an initial capacity of 16 characters. • Constructor that takes an integer argument • creates a StringBuilder with no characters in it and • the initial capacity specified by the integer argument. • Constructor that takes a String argument creates • a StringBuilder containing the characters in the argument. • The initial capacity is the number of characters in the argument + 16.

  20. Example

  21. More StringBuilder methods • charAt • returns the character at the specified index • getChars • Copies characters from a StringBuilder into a char array • setCharAt • Takes an int and a char arguments • Setting the character at specified position to the character argument • reverse • Reverses the content of a StringBuilder

  22. append, insert, delete, deleteCharAt methods • append • appends values of various types to end of StringBuilder • insert • inserts values at any position in a StringBuilder • delete • takes two indexes defining the portion to be deleted • deleteCharAt • takes a single index argument, index of character to delete

  23. Character

  24. Methods of Character class • isDigit • determines whether a character is a digit • isLetter • determines whether a character is a letter • isLetterOrDigit • determines whether a character is a letter or digit • isLowerCase/isUpperCase • determines whether a character is lowercase/uppercase

  25. Methods of Character class (cont’d) • toUpperCase • converts a character into its uppercase equivalent • toLowerCase • converts a character into its lowercase equivalent • charValue • returns the character stored in the object • equals • determines whether 2 characters have the same content

More Related