<!DOCTYPE html>
<html lang="it">
<head>
<title>Esempio Classi</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.BodyFormat
{
font-family: "Segoe UI",calibri, arial,helvetica;
font-size: 16px;
font-weight: normal;
color: #2c0e10;
background-color: #f8f6e6;
}
.ClsBold
{
font-weight: bold;
}
</style>
</head>
<body class="BodyFormat">
<script>
window.onload = MyFunOnLoad;
function MyFunOnLoad()
{
}
function Test1()
{
// Creo una Persona
let Persona1 = new Persona();
Persona1.Id = 123;
Persona1.Nome = "Mario";
Persona1.Cognome = "Rossi";
Persona1.DataNascita = new Date(2004, 11, 31, 0, 0, 0);
Persona1.Note = "A<br>\\n/d'e\"f?g!h&€ùZ";
// Trasformo la Persona1 in una stringa JSON (Oggetto -> JSON)
let Json1 = JSON.stringify(Persona1)
// Adesso lo posso mandare al server in formato JSON facendo attenzione ad encodare eventuali caratteri speciali con: encodeURIComponent(Json1);
// Supponiamo di aver ricevuto un elemento di Persona dal server attraverso una stringa Json2 in formato JSON
// Ritrasformo la stringa JSON in una Persona (JSON -> Oggetto)
let Json2 = Json1;
let Persona2 = JSON.parse(Json2);
// Ne cambio il nome per vedere la differenza da quella originaria
Persona2.Nome = "Mario Bis";
// Questo è un esempio di stringa Json contenente una lista di elementi Persona
let Json3 = "[{\"Id\":123,\"Nome\":\"Mario\",\"Cognome\":\"Rossi\",\"DataNascita\":\"2004-12-30T23:00:00.000Z\",\"Note\":\"A<br>\\\\n/d'e\\\"f?g!h&€ùZ\"},{\"Id\":124,\"Nome\":\"Luisa\",\"Cognome\":\"Bianchi\",\"DataNascita\":\"2005-12-30T23:00:00.000Z\",\"Note\":\"Ciao\"}]";
// Supponiamo di aver ricevuto Json3 da una chiamata ad un Web Services, ecco come ricreare una lista di Persona a partire dal Json3
let LstDatiPersona = JSON.parse(Json3);
let s = GetElemProperties(Persona1);
s += "--------------------------------------------------------------------------------\n"
s +=...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.