Skip to content

Instantly share code, notes, and snippets.

@uyu423
Last active July 24, 2016 17:21
Show Gist options
  • Save uyu423/19726330dd50ca7dbaa78d05a672df1f to your computer and use it in GitHub Desktop.
Save uyu423/19726330dd50ca7dbaa78d05a672df1f to your computer and use it in GitHub Desktop.
<head>
<title>JSON Basic</title>
<meta charset="utf-8"/>
</head>
<body>
<script>
/* Array and Object Definition */
var arr = [ "Yongwoo", 25, "Catholic Univ, of Korea", "Computer Science" ];
var obj = { "NAME" : "Yongwoo", "AGE" : 25, "UNIVERSITY" : "Catholic Univ, of Korea", "MAJOR" : "Computer Science" };
/* Array and Object Value Check */
document.write("<b>Normal String Arrary :</b> ", arr, "<br/>");
document.write("<br/><b>Normal Object</b><br/>");
for(var objVarName in obj) {
document.write(objVarName, " : ", obj[objVarName], "<br/>");
}
/* JSON Definition */
var json = '{ "NAME" : "Yongwoo", "AGE" : 25, "UNIVERSITY" : "Catholic Univ, of Korea", "MAJOR" : "Computer Science" }';
/* JSON Parse and Check */
var jsonObj = JSON.parse(json);
document.write("<br/><b>JSON Object</b><br/>");
for(var objVarName in jsonObj) {
document.write(objVarName, " : ", jsonObj[objVarName], "<br/>");
}
/* JON Object to JSON String */
var jsonStr = JSON.stringify(jsonObj);
document.write("<br/><b>JSON String Format :</b> ", jsonStr, "<br/>");
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment