<< Chapter < Page Chapter >> Page >

Complete script listings

Listing 16 . Json0130a.htm.

<!--01/26/14 Illustrates the differencebetween the syntax of a JavaScript object and a JSON string that looks a lot likea JavaScript object. Must parse the JSON string to turn it into a JavaScriptobject before processing it using JavaScript. Uses JSON.stringify to produce a JSON string from aJavaScript object. Uses JSON.parse to produce a JavaScript object froma JSON string.--><!DOCTYPE html><html><head><title>ParseJSON01</title></head><body><script>//Define a function function aMethod(){return true;};document.write("Create a JavaScript object."); var obj01 = {name:"Bill",age:31,method:aMethod};document.write( "<br/>Unsuccessful attempt to display object."); document.write("<br/>" + obj01); document.write("<br/>Display keys in object: "); for (var key in obj01) {if (obj01.hasOwnProperty(key)) { document.write(key + " ");}//end if }//end for loopdocument.write("<br/>Display values in object: "); document.write(obj01.name + ", "+ obj01.age + ", " + obj01.method()); document.write("<br/>Transform JavaScript object " + "into a JSON string.");// Note that the method does not become part of the // JSON string.var jsonstring = JSON.stringify(obj01); document.write("<br/>Display JSON string " + jsonstring ); document.write("<br/>Unsuccessful attempt to " + "access name and age.");document.write("<br/>" + jsonstring.name + ", " + jsonstring.age);document.write("<br/>Transform the JSON string " + "into a JavaScript object.");var obj02 = JSON.parse(jsonstring); document.write("<br/>Display values in object: "); document.write(obj02.name + ", " + obj02.age);document.write("<br/>Display keys in object: ");; // Note that it does not contain the method from the// original JavaScript object. for (var key in obj02) {if (obj02.hasOwnProperty(key)) { document.write(key + " ");}//end if }//end for loop</script></body></html>
Listing 17 . Json0130b.htm.
<!--01/26/14---------------------------------------------// Illustrates the difference between the syntax of aJavaScript object a JSON string that looks a lot like a JavaScript object where each involves array data. Mustparse the JSON text to turn it into a JavaScript object before processing it using JavaScript. --><!DOCTYPE html><html><head><title>ParseJSON02</title></head><body><script>document.write("Create a JavaScript object " + "involving array data.");var obj01 = {friends:[ {name:"Bill",age:31},{name:"Jill",age:40}]}; document.write("<br/>Display values in object."); document.write("<br/>" + obj01.friends[0].name +":" + obj01.friends[0].age);document.write("<br/>" + obj01.friends[1].name +":" + obj01.friends[1].age);document.write("<br/>Transform the object into a JSON string."); var jsontext = JSON.stringify(obj01);document.write("<br/>Display JSON string."); document.write("<br/>" + jsontext); document.write("<br/>Transform the JSON string " + "into a JavaScript object.");var obj02 = JSON.parse(jsontext); document.write("<br/>Display values in object."); document.write("<br/>" + obj02.friends[0].name+ ":" + obj02.friends[0].age);document.write("<br/>" + obj02.friends[1].name+ ":" + obj02.friends[1].age);</script></body></html>
Listing 18 . Json0130d.htm.
<!DOCTYPE html><html><body><script>var jScrObj01 = {"name":"John","age":33}; var jSonStr01 = '{"name":"Bill","age":33}';document.write("<br/>1. " + jScrObj01.name); document.write("<br/>2. " + jSonStr01.name);document.write("<br/>3. " + jScrObj01); document.write("<br/>4. " + jSonStr01);var jScrObj02 = JSON.parse(jSonStr01); var jSonStr02 = JSON.stringify(jScrObj01);document.write("<br/>5. " + jScrObj02.name); document.write("<br/>6. " + jSonStr02.name);document.write("<br/>7. " + jScrObj02); document.write("<br/>8. " + jSonStr02);</script></body></html>

-end-

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to xml. OpenStax CNX. Dec 02, 2014 Download for free at https://legacy.cnx.org/content/col11207/1.18
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to xml' conversation and receive update notifications?

Ask