Saturday, July 14, 2012

JSON

Hello



1. Introduction

JSON: Java Script Object Notation.
JSON is smaller and faster then XML , it is also parsed easier
JSON syntax used to store and exchange information


JSON example  :
{
"students": [
{ "firstName":"Jim" , "lastName":"Deer" },
{ "firstName":"Kim" , "lastName":"Wild" },
{ "firstName":"Jana" , "lastName":"Jampolski" }
]
} 

student is an array of three objects


XML similarities

  • JSON is simple text
  • JSON is "self-describing" (human readable)
  • JSON can be parsed by JavaScript
  • JSON data can be transported using AJAX
  • JSON is hierarchical (values within values)

XML dissimilarities

  • No end tag
  • Shorter
  • Uses arrays 
  • Quicker to write and read 
  • Can be parsed using built-in JavaScript eval()
  • No reserved words




Why JSON?
For AJAX applications, JSON is faster and easier than XML:


Using XML
  • Load an XML document
  • Use the XML DOM to read the document
  • Extract values and store in variables
Using JSON
  • Get a JSON string
  • eval() the JSON string


2. JSON Syntax


JSON syntax is a subset of JavaScript syntax

JSON Syntax Rules :

  • Data is in name/value pairs
  • Data is separated by comma
  • Square brackets holds arrays
  • Curly brackets holds objects



JSON Name/Value Pairs
JSON data is written as name/value pairs.
A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:
"firstName" : "Anna"


This is equals to the JavaScript statement:
firstName = " Anna "





JSON Values
JSON values can be 


  • A number (integer or floating point)
  • A string (in double quotes) 
  • A Boolean (true \ false)
  • An array (in square brackets)
  • An object (in curly brackets)
  • null




JSON Objects
JSON objects are written inside curly brackets,
Objects can contain multiple name/values pairs:
{ "firstName":"Anna" , "lastName":"Long" }


This is equals to the JavaScript statements:
firstName = " Anna "
lastName = "
Long "



JSON Arrays
JSON arrays are written inside square brackets.
An array can contain multiple objects:


{
"students": [
{ "firstName":"Pete" , "lastName":"Cool" },
{ "firstName":"Nathan" , "lastName":"Krasney" },
{ "firstName":"James" , "lastName":"Kid" }
]
}

In the example above, the object "students " is an array containing three objects. Each object is a record of a student (with a first name and a last name).



JSON Uses JavaScript Syntax

Because JSON uses JavaScript syntax, no extra software is needed to work with JSON within JavaScript.
With JavaScript you can create an array of objects and assign data to it like this:
Example
var  students = [
{ "firstName":"Pete" , "lastName":"Cool" },
{ "firstName":"Nathan" , "lastName":"Krasney" },
{ "firstName":"James" , "lastName":"Kid" }
];


The first entry in the JavaScript object array can be accessed like this:
students[0].lastName;
The returned content will be:
Cool

Nathan

Thursday, June 21, 2012

HTML based Web Site (chap 2 web beginners)

Hello

This chapter include the following :

  • Tools
  • HTML
  • Sample of web site with HTML page
  • Sample of web site with HTML pages , pictures , sound and video.


Tools

We will need the following tools for development of HTML based web site :

  • Browser
  • IIS
  • Visual Web Developer 2010
  • HTML
  • LoopBack (127.0.0.1)

Browser - allow HTTP GET to the web site


IIS :

  • Web server for hosting the web site and serving requests


Visual Web Developer 2010 :

  • development environment
  • free download


HTML :

  • markup language
  • used for static web site. I.e the info stored on the web site is delivered to the client as is. Dynamic web site may build the page on demand
  • http://www.w3schools.com/html/



LoopBack 

  • use for internal web site testing
  • use IP 127.0.0.1 or localhost



HTML (Hyper Text Markup Language)


Basic structure of HTML page


<HTML>
<HEAD>
                  <TITLE>
                            ................ title of the page
                  </TITLE>
 </HEAD>
  <BODY>
                            ................ body of the page
  </ BODY >

</HTML>


Tag list


remark - tag are not case sensitive


<br> - new line




div - it defines a section so we can e.g. apply the font to all of them
example :


<div align="center">
  This is some text center align!

<br>
text centered
</div>

<div align="left">
  This is some text  left align!
</div>
<div align="right">
  This is some text  right align!
</div>

This will create :


<p>
The <p> tag defines a paragraph.


<h1> ..... <h7> - heading
example :


<h1>big   heading </h1>
<br>
<h7>small heading </h7>


This will create :






Tag nesting
example :

<HEAD>
                  <TITLE>
                            ................ title of the page
                  </TITLE>
 </HEAD>



<hr> - line


example :


<hr color="blue"/>


<font>
example :


<font face="arial"  size="7"/>some text</font>
size is 1-7

This will create :



<big> - big text
<small> - small text
example :


<big>big text</big>
<small>small text</small>

This will create :




Sample of web site with HTML page


Run visual studio as administrator (Windows 7)


Create a new web site





Choose ASP.Net Empty Site, HTTP, and the location of the site




Open the IIS via "Control Panel"->"Administrative Tools"  and notice the name "WebSite" which we just created


Now we will add a new HTML pahe into the web site.




By adding HTML page


Now you can edit the page



It is possible check that the page is loading correctly (using HTTP GET) in few ways :

via the browser - http://localhost/WebSite/HTMLPage.htm

via the IDE -

in any way you will get the same result on the browser

Tag list continued


style

  • attribute
  • style determine the visual appearance
example :

<div style="background:green">
<h1>text</h1>
another text
</div>
<div style="background:red">
<h1>text</h1>
another text
</div>

This will create :

You can also use : background-color, text-align,color,font-family


test it yourself

<img> - using image
the basic structure is <img src="url"  width="pixel width" height=" pixel height"/>


example :

<img src="http://budgetstockphoto.com/freeimages/environment/pics/clean_beach6085.jpg"
    width="100" height="100"/>

will create:
<ol> - ordered list
<li> - list item


example :



<h4>An Ordered List:</h4>
<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>


will create :



<ul> - un ordered list

example :



<h4>An Un Ordered List:</h4>
<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>


will create :
<dl> - definition list
<dt> - subject item in definition list
<dd> - sub subject item in definition list


example :


<dl>
  <dt>Coffee</dt>
    <dd>- black hot drink</dd>

      <dd>- latte</dd> 
  <dt>Milk</dt>
    <dd>- white cold drink</dd>
</dl>



will create :
<table> - table
<tr> - define a row in a table
<th> - define a header cell in table
<td> - define standard cell in table


example :


<table border="1"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table>


will create :


common table attributes :
border = n , table width
cellspacing = n , space beteen cells
cellpadding = n , space inside cells
width = n , table width
bgcolor = color , table background color
colspan = n , number of columns cell should span
rowspan= n , number of rows cell should span


test it yourself !!



write hebrew
This require :

  • setting the encoding :
  • meta http-equiv="content-type" content="text/html;charset=UTF-8"
  • should be inside the head 
  • setting direction - dir=rtl

example :


<html > <HEAD> <meta http-equiv="content-type" content="text/html;charset=UTF-8"> </HEAD> <BODY dir=rtl> שלום חבר </ BODY > </html>


will create :
<fieldset> - Group related elements in a form


exanmple :
<form>
  <fieldset>
    Name: <input type="text" /><br />
    Email: <input type="text" /><br />
    Date of birth: <input type="text" />
  </fieldset>
</form>



Will create :




The <legend> tag defines a caption for the <fieldset> element.


<form>
  <fieldset>
    <legend>Personalia:</legend>
    Name: <input type="text" size="30" /><br />
    Email: <input type="text" size="30" /><br />
    Date of birth: <input type="text" size="10" />
  </fieldset>
</form>



Will create :




links
<a> - link


attributes :

  • href - URL
  • target - specify where to open the windows e.g. _blank is new windows



link may refer to :

  • html file
  • web site
  • picture
  • audio\video file
  • mail



example
<a href="http://www.w3schools.com">Visit W3Schools.com!</a>
<br>
<a href="http://budgetstockphoto.com/freeimages/environment/pics/clean_beach6085.jpg">Nice Picture</a>
<br>
<a href="mailto:nathan@nynkmobile.com">Nathan's e-mail</a>



will create :
you can click on the links


reamrk - link can be relative e.g. point to html inside the web site.
e.g. <a href="HTMLPage.htm">Load Local Page</a>






Sample of web site with HTML pages , pictures , sound and video.


we will create a project as before


and add directories :

  • pictures
  • cars
  • airplanes
  • sound
  • video

and main html file






download files.rar into your desktop and then add to the project








loading all the file result in :




Actually we will have 6 pages which are organized like a tree as follows

  • Main page
  • Picture page
  • Cars page
  • Airplanes page 
  • Video page
  • Sound page 



project (you need to create web site and add files from above zip)


Main Page :
Picture page :
Sound Page :
Video Page :




Cars Page :




Airplane Page :






Nathan

Thursday, April 5, 2012

REST api

Hello

What is REST ?

  • REST stand for Representional State Transfer.
  • It relies on stateless,client\server,cacheable communication protocol
  • Uses HTTP
  • Restfull applications use HTTP to post data (create/update) , read data (make queries) , and delete data


REST as Lightweight Web Service
Much like Web Services a REST service is :

  • Platform independent i.e. does not care if Windows,Mac,Linux ... is used
  • Language  independent i.e. Java,C#,...
  • Standard based (runs over HTTP)
  • Can easyly be used with firewalls

How simple is REST


To get a user details the follolwing query may be used :
http://www.acme.com/phonebook/UserDetailes/1234

1234 is the requested user id
UserDetailes is the desired info

This is a URL which is sent via HTTP GET request.

More complex REST request


http://www.acme.com/phonebook/UserDetailes?firstName=John&LastName=Doe

Nathan

Tuesday, January 10, 2012

ASP.Net WebMatrix - Simple User Interaction

Hello

http://www.microsoft.com/web/post/web-development-101-part-6-creating-an-add-data-page

Points of interest

  • WebMatrix has GREAT integration with Visual Studio 2010. You can launch VS and debug e.g. cshtml file - really great !!
  • Sending info to the server via browser :
  • HTTP POST is used (check this using Site->Requests)
  • HTML form is used
  • The server must identify the POST verb and process. Here it insert user inputs into a database 



Nathan

Monday, January 9, 2012

ASP.Net WebMatrix - Using Data Base

Hello

http://www.microsoft.com/web/post/web-development-101-part-5-using-data

Points of notice

  • Very nice integration of database in WebMatrix to allow easy database\table creation
  • Reuse of the layout that was done before using Razor and cshtml
  • Very simple access of database using Razor ( http://www.w3schools.com/razor/default.asp)


Nathan

ASP.Net WebMatrix - Using Layouts

Hello

http://www.microsoft.com/web/post/web-development-101-part-4-using-layout


Points of notice

  • cshtml file - HTML + C#\VB code
  • Razor  (layout reuse)
  • Run cshtml file and _PageStart.cshtml is invoked autmatically 

Nathan