تحليل استجابات JSON
استخرج الحقول باستخدام ArduinoJson.
تحليل استجابات JSON درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Responses Are Just Text
A server reply arrives as one long string. To use a value inside it, you first have to pull that value out cleanly.
Why Not Search by Hand
Hunting through text with indexOf is fragile. A real JSON parser understands the structure and gives you fields safely.
Meet ArduinoJson
The ArduinoJson library turns a JSON string into objects you can read by key. Install it from the Library Manager.
#include <ArduinoJson.h>Make a Document
Create a JsonDocument to hold the parsed data. It is the container ArduinoJson fills in for you.
JsonDocument doc;Parse the String
Call deserializeJson() with your document and the response text. This reads the string and fills the document.
deserializeJson(doc, body);Check for Errors
deserializeJson returns an error you should test. Bad or partial JSON should be caught before you trust any field.
if (deserializeJson(doc, body)) {
return; // parse failed
}Read a Field by Key
Access a value with its key, just like a dictionary. Tell ArduinoJson the type you expect for that field.
float temp = doc["temp"];Read Nested Values
For nested JSON, chain the keys. Each bracket steps one level deeper into the structure to reach the value you want.
int id = doc["device"]["id"];Loop Through an Array
If a field is a JSON array, you can walk it with a for loop and read each element in turn.
for (JsonVariant v : doc["list"].as<JsonArray>()) {
}Size the Document Right
A JsonDocument uses memory. Keep it just big enough for your data, since RAM on a microcontroller is limited.
Strings Need Care
Treat a parsed string as valid only while the source text still exists. Copy it out if you need it to last longer.
Quick Check
Which function actually converts the JSON text into a readable document?
Recap
You used ArduinoJson to deserialize a response, checked for errors, and read fields and arrays by key. Raw text is now real data. 🎉
الأسئلة الشائعة
هل درس «تحليل استجابات JSON» مجاني؟
نعم — نص درس «تحليل استجابات JSON» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
ماذا ستتعلم في «تحليل استجابات JSON»؟
استخرج الحقول باستخدام ArduinoJson. تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟
لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تحليل استجابات JSON»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟
نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- جلب البيانات من API باستخدام GET
- إرسال قراءات المستشعر باستخدام POST
- تحليل استجابات JSON
- استخدام HTTPS بأمان