JSON ﺖﺳﺍ ﻩﺩﺍﺩ ﻝﺎﻘﺘﻧﺍ ﻭ ﻩﺮﯿﺧﺫ ﯼﺍﺮﺑ ﯽﺘﻣﺮﻓ.
JSON ﺩﻮﺷ ﯽﻣ ﻝﺎﺳﺭﺍ ﺏﻭ ﻪﺑ ﺭﻭﺮﺳ ﺯﺍ ﺎﻫ ﻩﺩﺍﺩ ﻪﮐ ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﻧﺎﻣﺯ ﺐﻠﻏﺍ
JSON ﻒﻔﺨﻣ JavaScript Object Notation ﺖﺳﺍ
JSON ﺖﺳﺍ ﻥﺯﻭ ﮏﺒﺳ ﻩﺩﺍﺩ ﻝﺩﺎﺒﺗ ﺖﻣﺮﻓ ﮏﯾ
JSON ﻥﺎﺑﺯ ﺯﺍ ﻞﻘﺘﺴﻣ * ﺖﺳﺍ
JSON "ﺖﺳﺍ ﮎﺭﺩ ﻞﺑﺎﻗ ﯽﺘﺣﺍﺭ ﻪﺑ ﻭ ﺖﺳﺍ "ﻒﯿﺻﻮﺗ ﺩﻮﺧ
.ﺖﺳﺍ ﻦﺘﻣ ﻂﻘﻓ JSON ﺖﻣﺮﻓ ﺎﻣﺍ ،ﺖﺳﺍ ﻩﺪﺷ ﻖﺘﺸﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﯼﺭﺍﺬﮔ ﻪﻧﺎﺸﻧ ﻮﺤﻧ ﺯﺍ JSON ﻮﺤﻧ
:(ءﺎﯿﺷﺍ) ﺪﻨﻣﺭﺎﮐ ﺩﺭﻮﮐﺭ 3 ﺯﺍ ﯼﺍ ﻪﯾﺍﺭﺁ :ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﻥﺎﻨﮐﺭﺎﮐ ءﯽﺷ ﮏﯾ JSON ﻮﺤﻧ ﻦﯾﺍ
{
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}
ﺖﺳﺍ ﻥﺎﺴﮑﯾ ﺩﺎﺠﯾﺍ ﺪﮐ ﺎﺑ ﯼﻮﺤﻧ ﺮﻈﻧ ﺯﺍ JSON ﺖﻣﺮﻓ
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻣﺎﻧﺮﺑ ﮏﯾ ،ﺖﻫﺎﺒﺷ ﻦﯾﺍ ﻞﯿﻟﺩ ﻪﺑ
ﺪﻨﺘﺴﻫ ﺭﺍﺪﻘﻣ/ﻡﺎﻧ ﺖﻔﺟ ﺕﺭﻮﺻ ﻪﺑ ﺎﻫ ﻩﺩﺍﺩ
ﺪﻧﻮﺷ ﯽﻣ ﺍﺪﺟ ﻢﻫ ﺯﺍ ﺎﻣﺎﮐ ﺎﺑ ﺎﻫ ﻩﺩﺍﺩ
ﺪﻧﺭﺍﺩ ﯽﻣ ﻪﮕﻧ ﺍﺭ ﻡﺎﺴﺟﺍ ﯼﺮﻓﺮﻓ ﯼﺎﻫ ﺲﯾﺮﺑ
ﺪﻧﺭﺍﺩ ﯽﻣ ﻪﮕﻧ ﺍﺭ ﺎﻫ ﻪﯾﺍﺭﺁ ﻊﺑﺮﻣ ﯼﺎﻫ ﺖﮐﺍﺮﺑ
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺪﻨﻧﺎﻣ ﺖﺳﺭﺩ ،ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﺷﻮﻧ ﺭﺍﺪﻘﻣ/ﻡﺎﻧ ﺖﻔﺟ ﺕﺭﻮﺻ ﻪﺑ JSON ﯼﺎﻫ ﻩﺩﺍﺩ
.ﺖﺳﺍ ﻩﺪﺷ ﻞﯿﮑﺸﺗ (ﻪﻣﻮﯿﮔ ﻭﺩ ﺭﺩ) ﺪﻠﯿﻓ ﻡﺎﻧ ﮏﯾ ﺯﺍ ﺭﺍﺪﻘﻣ/ﻡﺎﻧ ﺖﻔﺟ ﮏﯾ
"firstName":"John"
.ﺩﺭﺍﺪﻧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻡﺎﻧ .ﺪﻧﺭﺍﺩ ﺯﺎﯿﻧ ﻪﻧﺎﮔﻭﺩ ﻝﻮﻗ ﻞﻘﻧ ﻪﺑ JSON ﯼﺎﻫ ﻡﺎﻧ
.ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﺷﻮﻧ ﺪﻌﺠﻣ ﯼﺎﻫﺰﺘﻧﺍﺮﭘ ﻞﺧﺍﺩ ﺭﺩ JSON ءﺎﯿﺷﺍ
:ﺪﻨﺷﺎﺑ ﺭﺍﺪﻘﻣ/ﻡﺎﻧ ﺖﻔﺟ ﻦﯾﺪﻨﭼ ﻞﻣﺎﺷ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ءﺎﯿﺷﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺪﻨﻧﺎﻣ ﺖﺳﺭﺩ
{"firstName":"John", "lastName":"Doe"}
.ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﺷﻮﻧ ﺰﺘﻧﺍﺮﭘ ﻞﺧﺍﺩ ﺭﺩ JSON ﯼﺎﻫ ﻪﯾﺍﺭﺁ
:ﺪﺷﺎﺑ ءﺎﯿﺷﺍ ﻞﻣﺎﺷ ﺪﻧﺍﻮﺗ ﯽﻣ ﻪﯾﺍﺭﺁ ﮏﯾ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺪﻨﻧﺎﻣ ﺖﺳﺭﺩ
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
ﺖﺳﺍ ﻪﺳ ﻞﻣﺎﺷ .ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﮏﯾ "ﻥﺍﺪﻨﻣﺭﺎﮐ" ﯽﺷ ،ﻻﺎﺑ ﻝﺎﺜﻣ ﺭﺩ
.ﺖﺳﺍ (ﯽﮔﺩﺍﻮﻧﺎﺧ ﻡﺎﻧ ﻭ ﻡﺎﻧ ﺎﺑ) ﺺﺨﺷ ﮏﯾ ﺩﺭﻮﮐﺭ ءﯽﺷ ﺮﻫ
.ﺖﺳﺍ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﺎﻫ ﻩﺩﺍﺩ ﻥﺪﻧﺍﻮﺧ JSON ﺞﯾﺍﺭ ﯼﺎﻫﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯽﮑﯾ
.ﺩﺍﺩ ﻥﺎﺸﻧ ﯼﺩﻭﺭﻭ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﻦﯾﺍ ،ﯽﮔﺩﺎﺳ ﯼﺍﺮﺑ
:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ JSON ﻮﺤﻧ ﯼﻭﺎﺣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﮏﯾ ﺍﺪﺘﺑﺍ
let text = '{ "employees" : [' +
'{ "firstName":"John" , "lastName":"Doe" },' +
'{ "firstName":"Anna" , "lastName":"Smith" },' +
'{ "firstName":"Peter" , "lastName":"Jones" } ]}';
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﻪﺑ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ JSON.pa
const obj = JSON.parse(text);
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﻪﺤﻔﺻ ﺭﺩ ﺪﯾﺪﺟ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺯﺍ ،ﺖﯾﺎﻬﻧ ﺭﺩ
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Create Object from JSON String</h2>
<p id="demo"></p>
<script>
let text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';
const obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
</script>
</body>
</html>
.ﺪﯿﻧﺍﻮﺨﺑ JSON ﺩﺭﻮﻣ ﺭﺩ ﯼﺮﺘﺸﯿﺑ ﺕﺎﻋﻼﻃﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻣ JSON ﺵﺯﻮﻣﺁ ﺭﺩ