0% found this document useful (0 votes)
32 views1 page

Code

Uploaded by

luongthedung0505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Code

Uploaded by

luongthedung0505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import json

class Order:
def __init__(self, json_data):
[Link] = [Link](json_data)
self.order_id = [Link]("order_id")
[Link] = Customer([Link]("customer"))
[Link] = [Item(item) for item in [Link]("items", [])]
class Customer:
def __init__(self, customer_data):
[Link] = customer_data.get("name")
[Link] = customer_data.get("email")
class Item:
def __init__(self, item_data):
self.product_id = item_data.get("product_id")
[Link] = item_data.get("quantity")
[Link] = item_data.get("price")
# Example usage
json_string = """{
"order_id": 12345,
"customer": {"name": "John Doe", "email": "johndoe@[Link]"},
"items": [
{"product_id": 1, "quantity": 2, "price": 19.99},
{"product_id": 2, "quantity": 1, "price": 9.99}
]
}"""
order = Order(json_string)
print("Order ID:", order.order_id)
print("Customer Name:", [Link])
print("Customer Email:", [Link])
for item in [Link]:
print(f"Product ID: {item.product_id}, Quantity: {[Link]}, Price: ${[Link]:.2f}")

You might also like