JSON ﺭﻭﺮﺳ


فهرست مطالب

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


.ﺖﺳﺍ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ/ﻪﺑ ﻩﺩﺍﺩ ﻝﺩﺎﺒﺗ ،JSON ﺞﯾﺍﺭ ﯼﺎﻫﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯽﮑﯾ

.ﺪﻨﺘﺴﻫ ﻪﺘﺷﺭ ﮏﯾ ﻪﺸﯿﻤﻫ ﺎﻫ ﻩﺩﺍﺩ ،ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﻩﺩﺍﺩ ﺖﻓﺎﯾﺭﺩ ﻡﺎﮕﻨﻫ

.ﺪﻧﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﻪﺑ ﺎﻫ ﻩﺩﺍﺩ ﻭ ﺪﯿﻨﮐ ﻪﯾﺰﺠﺗ J


ﺎﻫ ﻩﺩﺍﺩ ﻝﺎﺳﺭﺍ

ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﺍﺭ ﯽﺷ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﯾﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺭﺩ ﻩﺪﺷ ﻩﺮﯿﺧﺫ ﯼﺎﻫ ﻩﺩﺍﺩ ﺮﮔﺍ

ﻝﺎﺜﻣ

 const myObj = {name: "John", 
  age: 31, city: "New York"};
const myJSON = 
  JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;

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

<!DOCTYPE html>
<html>
<body>

<h2>Convert a JavaScript object into a JSON string, and send it to the server.</h2>

<script>
const myObj = { name: "John", age: 31, city: "New York" };
const myJSON = JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;
</script>

</body>
</html>

ﺕﺎﻋﻼﻃﺍ ﺖﻓﺎﯾﺭﺩ ﻝﺎﺣ ﺭﺩ

ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ ﻥﺁ ﯽﺘﺣﺍﺭ ﻪﺑ ﺪﯿﻧﺍﻮﺗﯽﻣ ،ﺪﯿﻨﮐﯽﻣ ﺖﻓﺎﯾﺭﺩ JSON ﺖﻣﺮﻓ

ﻝﺎﺜﻣ

 const myJSON =
  '{"name":"John", 
  "age":31, "city":"New York"}';
const myObj = 
  JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;

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

<!DOCTYPE html>
<html>
<body>

<h2>Convert a JSON string into a JavaScript object.</h2>

<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":31, "city":"New York"}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;
</script>

</body>
</html>

JSON ﺭﻭﺮﺳ ﮏﯾ ﺯﺍ

ﺪﯿﻨﮐ ﺖﺳﺍﻮﺧﺭﺩ ﺭﻭﺮﺳ ﺯﺍ ﺍﺭ JSON ﺪﯿﻧﺍﻮﺗ ﯽﻣ AJAX ﺖﺳﺍﻮﺧﺭﺩ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ

ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﺷﺎﺑ ﻩﺪﺷ ﻪﺘﺷﻮﻧ JSON ﺖﻣﺮﻓ ﺎﺑ ﺭﻭﺮﺳ ﺦﺳﺎﭘ ﻪﮐ ﯽﻧﺎﻣﺯ ﺎﺗ

ﻝﺎﺜﻣ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺭﻭﺮﺳ ﺯﺍ ﻩﺩﺍﺩ ﺖﻓﺎﯾﺭﺩ ﯼﺍﺮﺑ XMLHttpRequest ﺯﺍ

const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
  const myObj = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myObj.name;
};
xmlhttp.open("GET", "json_demo.txt");
xmlhttp.send();

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

<!DOCTYPE html>
<html>
<body>

<h2>Fetch a JSON file with XMLHttpRequest</h2>
<p id="demo"></p>

<script>
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
  const myObj = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myObj.name;
}
xmlhttp.open("GET", "json_demo.txt");
xmlhttp.send();
</script>

</body>
</html>

https://basicit.org/js/json_demo.txt :ﺪﯾﺯﺍﺪﻨﯿﺑ ﯽﻫﺎﮕﻧ json_demo.txt ﻪﺑ



JSON ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﯾﺍﺭﺁ

ﺵﻭﺭ ،ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﻩﺪﺷ ﻖﺘﺸﻣ JSON ﺭﺩ JSON.parse() ﺯﺍ ﻩﺩ

ﻝﺎﺜﻣ

JSON ﺪﺷ ﻩﺪﻧﺍﺩﺮﮔﺮﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺭﻭﺮﺳ ﮏﯾ ﺯﺍ:

const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
  const myArr = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myArr[0];
  }
}
xmlhttp.open("GET", "json_demo_array.txt", true);
xmlhttp.send();

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

<!DOCTYPE html>
<html>
<body>

<h2>Fetch a JSON file with XMLHttpRequest</h2>
<p>Content written as an JSON array will be converted into a JavaScript array.</p>
<p id="demo"></p>

<script>
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
  const myArr = JSON.parse(this.responseText);
  document.getElementById("demo").innerHTML = myArr[0];
}
xmlhttp.open("GET", "json_demo_array.txt", true);
xmlhttp.send();
</script>

</body>
</html>

https://basicit.org/js/json_demo_array.txt :ﺪﯾﺯﺍﺪﻨﯿﺑ ﯽﻫﺎﮕﻧ json_demo_array.txt ﻪﺑ