JSON을 사용하여 http://jsonlint.com/을 확인하고 json2csharp.com을 사용하여 C# 클래스를 만들었습니다.JSON을 C#으로 클래스에 비 직렬화
JSON.Net, RestSharp, .Net DataContractJsonSerializer 및 JavaScriptSerializer로 deserialize를 시도했지만 아무 것도 작동하지 않았습니다. 클래스는 항상 비어 있으며 오류가 발생하지 않습니다.
여기에 지정된대로 JSON.Net을 사용하여 디버깅을 활성화했지만 오류는 발생하지 않았습니다.
기본 속성 몇 가지 만 있으면 필요한 간단한 Invoice 클래스 (목록 없음)를 사용해 보았습니다.
내가 잘못하고있는 것에 대한 아이디어는 인정 될 것입니다.
Invoice ret = JsonConvert.DeserializeObject<Invoice>(results.Content);
RestSharp를 통해 .Content에 반환되는 JSON입니다.
{
"code": 0,
"message": "success",
"invoice": {
"invoice_id": "464323000000255001",
"invoice_number": "993301",
"date": "2014-03-01",
"status": "draft",
"payment_terms": 0,
"payment_terms_label": "Due on Receipt",
"due_date": "2014-03-01",
"payment_expected_date": "",
"last_payment_date": "",
"reference_number": "",
"customer_id": "464323000000194095",
"customer_name": "User, Test",
"contact_persons": [],
"currency_id": "464323000000005001",
"currency_code": "USD",
"currency_symbol": "$",
"exchange_rate": 1,
"discount": 0,
"is_discount_before_tax": true,
"discount_type": "item_level",
"recurring_invoice_id": "",
"is_viewed_by_client": false,
"line_items": [
{
"line_item_id": "464323000000255009",
"item_id": "464323000000047609",
"project_id": "",
"time_entry_ids": "",
"expense_id": "",
"expense_receipt_name": "",
"name": "Management Fees",
"description": "Testing invoice update",
"item_order": 0,
"bcy_rate": 1,
"rate": 1,
"quantity": 1,
"unit": "",
"discount_amount": 0,
"discount": 0,
"tax_id": "",
"tax_name": "",
"tax_type": "tax",
"tax_percentage": 0,
"item_total": 1
},
{
"line_item_id": "464323000000255011",
"item_id": "464323000000047609",
"project_id": "",
"time_entry_ids": "",
"expense_id": "",
"expense_receipt_name": "",
"name": "Management Fees",
"description": "Another test",
"item_order": 1,
"bcy_rate": 2,
"rate": 2,
"quantity": 1,
"unit": "",
"discount_amount": 0,
"discount": 0,
"tax_id": "",
"tax_name": "",
"tax_type": "tax",
"tax_percentage": 0,
"item_total": 2
}
],
"shipping_charge": 0,
"adjustment": 0,
"adjustment_description": "Adjustment",
"late_fee": {
"name": "",
"type": "percentage",
"rate": 0,
"amount": 0,
"frequency_type": "month"
},
"sub_total": 3,
"tax_total": 0,
"total": 3,
"taxes": [],
"payment_reminder_enabled": true,
"payment_made": 0,
"credits_applied": 0,
"tax_amount_withheld": 0,
"balance": 3,
"write_off_amount": 0,
"allow_partial_payments": false,
"price_precision": 2,
"payment_options": {
"payment_gateways": []
},
"is_emailed": false,
"reminders_sent": 0,
"last_reminder_sent_date": "",
"billing_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"shipping_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"notes": "Thanks for your business.",
"terms": "",
"custom_fields": [],
"template_id": "464323000000025001",
"template_name": "Standard Template",
"template_type": "standard",
"created_time": "2014-02-21T08:39:11-0500",
"last_modified_time": "2014-02-21T08:39:11-0500",
"attachment_name": "",
"can_send_in_mail": true,
"salesperson_id": "",
"salesperson_name": "",
"invoice_url": ""
}}
감사합니다. Json.Net만을 사용할 때 이것을 처음 시도했는데 "입력 문자열이 올바른 형식이 아니 었습니다"라는 오류가 발생하여 다른 시도를 수행했습니다. 입력 문자열 문제는 속성 중 하나가 Int이고 값이 10 진수로 인해 발생했습니다. 그 시점에서 근시가 시작되었고 나는 나무 숲을 볼 수 없었습니다 ... – topry