JSON Literals


فهرست مطالب

    نمایش فهرست مطالب


:ﺖﺳﺍ JSON ﻪﺘﺷﺭ ﮏﯾ ﻦﯾﺍ

'{"name":"John", "age":30, "car":null}'

:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﻤﻠﮐ ﯽﻌﻗﺍﻭ ﯼﺎﻨﻌﻣ ﻪﺑ JSON ﯽﺷ ﮏﯾ JSON ﻪﺘﺷﺭ ﻞﺧﺍﺩ ﺭﺩ

{"name":"John", "age":30, "car":null}

.ﺪﻧﺍ ﻩﺪﺷ ﻪﻃﺎﺣﺍ {} ﺪﻌﺠﻣ ﯼﺎﻫﺰﺘﻧﺍﺮﭘ ﻂﺳﻮﺗ JSON ءﯽﺷ ﯼﺎﺒﻔﻟﺍ ﻑﻭﺮﺣ

.ﺖﺳﺍ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﺖﻔﺟ ﯼﻭﺎﺣ ءﯽﺷ JSON ﻑﺮﺣ

.ﺪﻧﻮﺷ ﯽﻣ ﺍﺪﺟ ﻢﻫ ﺯﺍ ﻪﻄﻘﻧ ﻭﺩ ﺎﺑ ﺮﯾﺩﺎﻘﻣ ﻭ ﺎﻫﺪﯿﻠﮐ

،ﺪﻨﺷﺎﺑ ﯼﺍ ﻪﺘﺷﺭ ﺪﯾﺎﺑ ﺎﻫﺪﯿﻠﮐ

.ﺩﻮﺷ ﯽﻣ ﺍﺪﺟ ﻢﻫ ﺯﺍ ﺎﻣﺎﮐ ﺎﺑ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﺖﻔﺟ ﺮﻫ

.ﻢﯿﻣﺎﻨﺑ "JSON ﯽﺷ ﮏﯾ" ﯽﻈﻔﻠﻟﺍ ﺖﺤﺗ ﺍﺭ JSON ﯽﺷ ﮏﯾ ﻪﮐ ﺖﺳﺍ ﺞﯾﺍﺭ ﻩﺎﺒﺘﺷﺍ ﮏﯾ ﻦﯾﺍ

JSON ﺪﺷﺎﺑ ﯽﺷ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻤﻧ. JSON ﺖﺳﺍ ﯼﺍ ﻪﺘﺷﺭ ﺖﻣﺮﻓ ﮏﯾ.

.ﺪﻨﺘﺴﻫ JSON ﻂﻘﻓ ﺪﻨﺷﺎﺑ ﯼﺍ ﻪﺘﺷﺭ ﺐﻟﺎﻗ ﺭﺩ ﺎﻫ ﻩﺩﺍﺩ ﻪﮐ ﯽﻧﺎﻣﺯ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ

:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﻤﻠﮐ ﯽﻌﻗﺍﻭ ﯼﺎﻨﻌﻣ ﻪﺑ JSON ﯽﺷ ﮏﯾ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

ﻝﺎﺜﻣ

myObj = {"name":"John", "age":30, "car":null};

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Creating an Object from a JSON Literal</h2>
<p id="demo"></p>

<script>
const myObj = {"name":"John", "age":30, "car":null};
document.getElementById("demo").innerHTML = myObj.name;
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ JSON ﻪﺘﺷﺭ ﮏﯾ ﻪﯾﺰﺠﺗ ﺎﺑ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺎﻤﺷ ،ﻝﻮﻤﻌﻣ ﺭﻮﻃ ﻪﺑ

ﻝﺎﺜﻣ

myJSON = '{"name":"John", "age":30, "car":null}';
myObj = JSON.parse(myJSON);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Creating an Object Parsing JSON</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;
</script>

</body>
</html>

ﯽﺷ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

:ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﯽﺷ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ (.) ﻪﻄﻘﻧ ﺖﻣﻼﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ

ﻝﺎﺜﻣ

const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
  x = myObj.name;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Access a JavaScript Object</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﯽﺷ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ([]) ﺖﮐﺍﺮﺑ ﯼﺭﺍﺬﮔﺖﻣﻼﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺪﯿﻧﺍﻮﺗﯽﻣ

ﻝﺎﺜﻣ

const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
  x = myObj["name"];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Access a JavaScript Object</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj["name"];
</script>

</body>
</html>


ﯽﺷ ﮏﯾ ﻥﺩﺯ ﻪﻘﻠﺣ

:ﺪﯿﻧﺰﺑ ﻪﻘﻠﺣ ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻖﯾﺮﻃ ﺯﺍ for-in ﻪﻘﻠﺣ ﮏﯾ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

ﻝﺎﺜﻣ

const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);

let text = "";
for (const x in myObj) {
  text += x + ", ";
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Looping Object Properties</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);

let text = "";
for (const x in myObj) {
  text += x + ", ";
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ values ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﺖﮐﺍﺮﺑ ﺩﺎﻤﻧ ﺯﺍ ،for-in ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ

ﻝﺎﺜﻣ

const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);

let text = "";
for (const x in myObj) {
  text += myObj[x] + ", ";
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Looping JavaScript Object Values</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);

let text = "";
for (const x in myObj) {
  text += myObj[x] + ", ";
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>