0Pricing
No-Code Automation · บทเรียน

การแยกวิเคราะห์การตอบกลับ JSON และ XML

เชี่ยวชาญเทคนิคการดึงข้อมูลที่เกี่ยวข้องจากข้อมูล JSON และ XML ที่ซับซ้อนซึ่งได้รับจากการเรียกใช้ API

การแยกวิเคราะห์การตอบกลับ JSON และ XML เป็นบทเรียน No-Code Automation ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน No-Code Automation และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส No-Code Automation มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Parse API Responses?

When you make an API call or receive a webhook, the data often comes in a structured format like JSON or XML. To use this data in your automation, you need to "parse" it.

Parsing means extracting specific pieces of information from a larger block of structured data. It's like finding a specific ingredient in a recipe. Without parsing, all you have is a raw string of text, which isn't very useful.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It's human-readable and easy for machines to parse and generate.

It's built on two structures:

  • Objects: Collections of name/value pairs, like a dictionary or map. Surrounded by curly braces {}.
  • Arrays: Ordered lists of values, like a list. Surrounded by square brackets [].

Here's a simple JSON object:

{
  "name": "Coddy",
  "age": 3,
  "isStudent": true
}

Common JSON Data Types

JSON supports several data types:

  • Strings: Text enclosed in double quotes (e.g., "Hello")
  • Numbers: Integers or floating-point (e.g., 123, 3.14)
  • Booleans: true or false
  • Null: Represents an empty or non-existent value (null)
  • Objects: Nested {} structures
  • Arrays: Nested [] lists

Understanding these types helps you know what kind of data to expect.

Extracting Values from JSON

To get a value from a JSON object, you typically refer to its "key" (the name). In no-code tools, this often looks like a field selector.

Let's say we want the "name" and "age" from our previous example. We'd target these keys.

import json

data_string = '{"name": "Coddy", "age": 3, "isStudent": true}'
data = json.loads(data_string)

print(data["name"])
print(data["age"])

Working with Nested JSON

JSON can have objects inside objects, creating a "nested" structure. To access data in nested objects, you chain the keys.

Imagine a user object with an address object inside it:

{
  "user": {
    "firstName": "Jane",
    "lastName": "Doe",
    "address": {
      "street": "123 Main St",
      "city": "Anytown"
    }
  }
}

Accessing Nested Data

To get the "city" from the nested example, you'd go through user, then address, then city. No-code platforms often represent this with dot notation (e.g., user.address.city) or nested selectors.

import json

nested_data_string = '''
{
  "user": {
    "firstName": "Jane",
    "lastName": "Doe",
    "address": {
      "street": "123 Main St",
      "city": "Anytown"
    }
  }
}
'''
data = json.loads(nested_data_string)

print(data["user"]["address"]["city"])

Handling JSON Arrays (Lists)

JSON arrays are ordered lists of values. These values can be strings, numbers, or even other objects! When an API returns a list of items, it's often in an array.

You often need to loop through arrays to process each item. In no-code tools, this is handled by "Iterator" or "Loop" modules.

{
  "products": [
    {"id": 1, "name": "Laptop"},
    {"id": 2, "name": "Mouse"},
    {"id": 3, "name": "Keyboard"}
  ]
}

Understanding XML

XML (Extensible Markup Language) is another popular format for data exchange, especially in older systems or specific industries. It uses tags to define elements, similar to HTML.

XML documents have a hierarchical structure, starting with a root element. Each element can have attributes (like properties) and child elements.

Here's a basic XML example:

<root>
  <item id="1">
    <name>Product A</name>
    <price>19.99</price>
  </item>
  <item id="2">
    <name>Product B</name>
    <price>29.99</price>
  </item>
</root>

Accessing XML Data

Extracting data from XML involves navigating its tree-like structure. You identify elements by their tag names and can access their text content or attributes.

No-code platforms provide specific modules to parse XML, allowing you to select elements by path or iterate through child elements.

import xml.etree.ElementTree as ET

xml_string = '''
<root>
  <item id="1">
    <name>Product A</name>
    <price>19.99</price>
  </item>
  <item id="2">
    <name>Product B</name>
    <price>29.99</price>
  </item>
</root>
'''
root = ET.fromstring(xml_string)

# Find the first item's name
first_item_name = root.find('item/name').text
print(f"First item name: {first_item_name}")

# Find an attribute
second_item_id = root.findall('item')[1].get('id')
print(f"Second item ID: {second_item_id}")

Quick Check: Data Extraction

Consider the following JSON response from an API:

{
  "order": {
    "orderId": "XYZ789",
    "customer": {
      "id": 101,
      "email": "test@example.com"
    },
    "items": [
      {"itemId": "A1", "quantity": 2},
      {"itemId": "B2", "quantity": 1}
    ]
  }
}

Recap: Parsing API Responses

We've covered the essentials of parsing JSON and XML data, which are crucial for working with APIs and webhooks.

  • JSON uses objects {} and arrays [], accessed by keys or indices.
  • XML uses tags <element> and attributes, accessed by navigating its hierarchical structure.
  • No-code platforms provide specialized modules (like "Parse JSON" or "XML Parser") to help you extract the data you need for your automations.

Mastering parsing allows you to unlock the full potential of integrated applications!

คำถามที่พบบ่อย

บทเรียน “การแยกวิเคราะห์การตอบกลับ JSON และ XML” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การแยกวิเคราะห์การตอบกลับ JSON และ XML” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส No-Code Automation ให้อัปเกรดเป็น CoddyKit PRO คอร์ส No-Code Automation มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การแยกวิเคราะห์การตอบกลับ JSON และ XML”

เชี่ยวชาญเทคนิคการดึงข้อมูลที่เกี่ยวข้องจากข้อมูล JSON และ XML ที่ซับซ้อนซึ่งได้รับจากการเรียกใช้ API คุณปฏิบัติ No-Code Automation ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน No-Code Automation หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน No-Code Automation บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การแยกวิเคราะห์การตอบกลับ JSON และ XML” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน No-Code Automation นี้ได้ไหม

ได้ บทเรียน No-Code Automation ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ทำความเข้าใจ Webhook สำหรับระบบอัตโนมัติ
  2. การเรียกใช้ API ในเวิร์กโฟลว์
  3. การแยกวิเคราะห์การตอบกลับ JSON และ XML
  4. การแบ่งหน้าและขีดจำกัดอัตราในการเรียกส่วนเชื่อมต่อโปรแกรมประยุกต์
← กลับไปที่ No-Code Automation