.ﺖﺳﺍ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ/ﻪﺑ ﻩﺩﺍﺩ ﻝﺩﺎﺒﺗ ،JSON ﺞﯾﺍﺭ ﯼﺎﻫﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯽﮑﯾ
.ﺪﻨﺘﺴﻫ ﻪﺘﺷﺭ ﮏﯾ ﻪﺸﯿﻤﻫ ﺎﻫ ﻩﺩﺍﺩ ،ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﻩﺩﺍﺩ ﺖﻓﺎﯾﺭﺩ ﻡﺎﮕﻨﻫ
.ﺪﻧﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﻪﺑ ﺎﻫ ﻩﺩﺍﺩ ﻭ ﺪﯿﻨﮐ ﻪﯾﺰﺠﺗ J
:ﻢﯾﺍ ﻩﺩﺮﮐ ﺖﻓﺎﯾﺭﺩ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﺍﺭ ﻦﺘﻣ ﻦﯾﺍ ﺪﯿﻨﮐ ﺭﻮﺼﺗ
'{"name":"John", "age":30, "city":"New York"}'
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﻪﺑ ﻦﺘﻣ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ JSON.par
const obj = JSON.parse('{"name":"John", "age":30, "city":"New
York"}');
.ﺪﺷ ﺪﯿﻫﺍﻮﺧ ﻪﺟﺍﻮﻣ ﯼﻮﺤﻧ ﯼﺎﻄﺧ ﮏﯾ ﺎﺑ ﺕﺭﻮﺻ ﻦﯾﺍ ﺮﯿﻏ ﺭﺩ ،ﺪﺷﺎﺑ JSON ﺖﻣﺮﻓ ﺎﺑ ﻦﺘﻣ ﻪﮐ ﺪﯾﻮﺷ ﻦﺌﻤﻄﻣ
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﻪﺤﻔﺻ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺯﺍ
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = obj.name;
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Creating an Object from a JSON String</h2>
<p id="demo"></p>
<script>
const txt = '{"name":"John", "age":30, "city":"New York"}'
const obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;
</script>
</body>
</html>
ﺵﻭﺭ ،ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﻩﺪﺷ ﻖﺘﺸﻣ JSON ﺭﺩ JSON.parse()
ﺯﺍ ﻩﺩ
const text = '["Ford", "BMW", "Audi", "Fiat"]';
const myArr = JSON.parse(text);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Parsing a JSON Array.</h2>
<p>Data written as an JSON array will be parsed into a JavaScript array.</p>
<p id="demo"></p>
<script>
const text = '[ "Ford", "BMW", "Audi", "Fiat" ]';
const myArr = JSON.parse(text);
document.getElementById("demo").innerHTML = myArr[0];
</script>
</body>
</html>
.ﺪﻨﺘﺴﯿﻧ ﺯﺎﺠﻣ JSON ﺭﺩ ﺦﯾﺭﺎﺗ ءﺎﯿﺷﺍ
.ﺪﯿﺴﯾﻮﻨﺑ ﯼﺍ ﻪﺘﺷﺭ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﻥﺁ ،ﺪﯾﺭﺍﺩ ﺦﯾﺭﺎﺗ ﺮﮐﺫ ﻪﺑ ﺯﺎﯿﻧ ﺮﮔﺍ
:ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﺦﯾﺭﺎﺗ ﯽﺷ ﮏﯾ ﻪﺑ ﻩﺭﺎﺑﻭﺩ ﺍﺭ ﻥﺁ ﺍًﺪﻌﺑ ﺪﯿﻧﺍﻮﺗﯽﻣ
:ﺦﯾﺭﺎﺗ ﻪﺑ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ
const text =
'{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text);
obj.birth = new Date(obj.birth);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Convert a string into a date object.</h2>
<p id="demo"></p>
<script>
const text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text);
obj.birth = new Date(obj.birth);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ reviver ﻡﺎﻧ ﻪﺑ JSON.parse()
ﻊ
.ﺪﻨﮐ ﯽﻣ ﯽﺳﺭﺮﺑ ﺍﺭ ﯽﮔﮋﯾﻭ ﺮﻫ ﻪﮐ ﺖﺳﺍ ﯽﻌﺑﺎﺗ reviver ﺮﺘﻣﺍﺭﺎﭘ
:ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﺦﯾﺭﺎﺗ ﻪﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ reviver ﻊﺑﺎﺗ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ
const text =
'{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text, function (key, value) {
if
(key == "birth") {
return new
Date(value);
} else {
return value;
}
});
document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Convert a string into a date object.</h2>
<p id="demo"></p>
<script>
const text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text, function (key, value) {
if (key == "birth") {
return new Date(value);
} else {
return value;
}
});
document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
</script>
</body>
</html>
.ﺪﻨﺘﺴﯿﻧ ﺯﺎﺠﻣ JSON ﺭﺩ ﻊﺑﺍﻮﺗ
.ﺪﯿﺴﯾﻮﻨﺑ ﯼﺍ ﻪﺘﺷﺭ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﻥﺁ ،ﺪﯾﺭﺍﺩ ﻊﺑﺎﺗ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﻪﺑ ﺯﺎﯿﻧ ﺮﮔﺍ
:ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻊﺑﺎﺗ ﮏﯾ ﻪﺑ ﺍﺭ ﻥﺁ ﺍًﺪﻌﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ
:ﻊﺑﺎﺗ ﻪﺑ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ
const text =
'{"name":"John", "age":"function () {return
30;}", "city":"New York"}';
const obj = JSON.parse(text);
obj.age = eval("(" + obj.age + ")");
document.getElementById("demo").innerHTML = obj.name + ", " +
obj.age();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Convert a string into a function.</h2>
<p id="demo"></p>
<script>
const text = '{"name":"John", "age":"function() {return 30;}", "city":"New York"}';
const obj = JSON.parse(text);
obj.age = eval("(" + obj.age + ")");
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age();
</script>
</body>
</html>
،ﺩﺍﺩ ﺪﻨﻫﺍﻮﺧ ﺖﺳﺩ ﺯﺍ ﺍﺭ ﺩﻮﺧ ﻪﻨﻣﺍﺩ ﻊﺑﺍﻮﺗ ،ﺪﯿﻨﮐ ﺏﺎﻨﺘﺟﺍ JSON ﺭﺩ ﻊﺑﺍﻮﺗ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺯﺍ ﺪﯾﺎﺑ