JavaScript JSON အမှတ်ပြု
JSON (JavaScript Object Notation, JavaScript ကိုယ်စားပြုမှု)
JSON is a format used for storing and transmitting data.
JSON is text, text can be transmitted anywhere, and can be read by any programming language.
JavaScript objects can be converted to JSON, and JSON can be converted back to JavaScript objects.
Thus, we can use the data as a JavaScript object without complex parsing or conversion.
အကြိုးအား
Send JSON:
// JavaScript object...: var myObj = { "name":"Bill", "age":19, "city":"Seattle" }; // ...Convert to JSON: var myJSON = JSON.stringify(myObj); // Send JSON: window.location = "demo_json.php?x=" + myJSON;
JSON အကျဉ်းချုပ် ပိုမို သိရှိရန် ကျမ်းကို ဖတ်ပါ JSON ဖော်ပြ.
JSON methods
Method | Description |
---|---|
parse() | Parse a JSON string and return a JavaScript object. |
stringify() | Convert a JavaScript object to a JSON string. |
Valid data types
In JSON, values must be one of the following data types:
- string
- number
- object (contains valid JSON values)
- array
- boolean
- null
JSON အရ အခြား အချက်အလက် အမျိုးအစား မပါဘူး:
- လုပ်ငန်း
- ရက်စွဲ
- undefined
ပိုမို အကြိုးအား
အကြိုးအား
သဘောတူ JSON လက်ခံ:
// myJSON က သဘောတူ JSON ပုံစံအဖြစ် လက်ခံ: // သဘောတူ JSON ကို JavaScript အပေါင်းအလုံး ပြောင်းလဲ: var myObj = JSON.parse(myJSON); document.getElementById("demo").innerHTML = myObj.name;
အကြိုးအား
localStorage အသုံးပြု၍ သဘောတူ အချက်အလက် JSON အဖြစ် ထိန်းသိမ်း:
// သဘောတူ ထိန်းသိမ်း: myObj = { "name":"Bill", "age":19, "city":"Seattle" }; myJSON = JSON.stringify(myObj); localStorage.setItem("testJSON", myJSON); // သဘောတူ ပြန်လည်ရယူ: text = localStorage.getItem("testJSON"); obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.name;
JSON အကျဉ်းချုပ် ပိုမို သိရှိရန် ကျမ်းကို ဖတ်ပါ JSON ဖော်ပြ.