JSON ﯼﺎﻫ ﻪﯾﺍﺭﺁ


فهرست مطالب

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

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

'["Ford", "BMW", "Fiat"]'

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

["Ford", "BMW", "Fiat"]

.ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﺑﺎﺸﻣ ﺎًﺒﯾﺮﻘﺗ JSON ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ

ﺪﺷﺎﺑ string، number، object، array، boolean ﻉﻮﻧ ﺯﺍ ﺪﯾﺎﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ،JSON ﺭﺩ

ﺪﻨﺷﺎﺑ ﯼﺮﮕﯾﺩ ﺮﺒﺘﻌﻣ ﺮﻫ ﻪﻓﺎﺿﺍ ﻪﺑ ﻻﺎﺑ ﺩﺭﺍﻮﻣ ﻪﻤﻫ ﺪﻨﻧﺍﻮﺗﯽﻣ ﺎﻫﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ،ﺖﭙﯾﺮﮑﺳ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﯾﺍﺭﺁ

ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ Literal ﮏﯾ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

ﻝﺎﺜﻣ

myArray = ["Ford", "BMW", "Fiat"];

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

<!DOCTYPE html>
<html>
<body>
<h2>Creating an Array from a Literal</h2>
<p id="demo"></p>

<script>
const myArray = ["Ford", "BMW", "Fiat"];
document.getElementById("demo").innerHTML = myArray;
</script>

</body>
</html>

ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ JSON ﻪﺘﺷﺭ ﻪﯾﺰﺠﺗ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

myJSON = '["Ford", "BMW", "Fiat"]';
myArray = JSON.parse(myJSON);

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

<!DOCTYPE html>
<html>
<body>

<h2>Creating an Array from JSON</h2>
<p id="demo"></p>

<script>
const myJSON = '["Ford", "BMW", "Fiat"]';
const myArray = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myArray;
</script>

</body>
</html>

ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

:ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺺﺧﺎﺷ ﺱﺎﺳﺍ ﺮﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺎﻤﺷ

ﻝﺎﺜﻣ

myArray[0];

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

<!DOCTYPE html>
<html>
<body>

<h1>Access an Array by Index</h1>
<p id="demo"></p>

<script>
const myJSON = '["Ford", "BMW", "Fiat"]';
const myArray = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myArray[0];
</script>

</body>
</html>

ﺎﯿﺷﺍ ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ

:ﺪﻨﺷﺎﺑ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ ﯼﻭﺎﺣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﯿﺷﺍ

ﻝﺎﺜﻣ

{
"name":"John",
"age":30,
"cars":["Ford", "BMW", "Fiat"]
}

:ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺺﺧﺎﺷ ﺱﺎﺳﺍ ﺮﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺎﻤﺷ

ﻝﺎﺜﻣ

myObj.cars[0];

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

<!DOCTYPE html>
<html>
<body>

<h2>Access Array Values</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);

document.getElementById("demo").innerHTML = myObj.cars[0];
</script>

</body>
</html>


ﻪﯾﺍﺭﺁ ﮏﯾ ﻖﯾﺮﻃ ﺯﺍ ﻥﺩﺯ ﻪﻘﻠﺣ

:ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ for in

ﻝﺎﺜﻣ

for (let i in myObj.cars) {
  
  x 
  += myObj.cars[i];
}

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

<!DOCTYPE html>
<html>
<body>

<h2>Looping an Array</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);

let text = "";
for (let i in myObj.cars) {
  text += myObj.cars[i] + ", ";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ for ﻪﻘﻠﺣ ﮏﯾ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﯾ

ﻝﺎﺜﻣ

 for (let i 
  = 0; i < myObj.cars.length; i++) {
  x 
  += myObj.cars[i];
}

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

<!DOCTYPE html>
<html>
<body>

<h2>Looping an Array</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);

let text = "";
for (let i = 0; i < myObj.cars.length; i++) {
  text += myObj.cars[i] + ", ";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>