我目前正在嘗試創建發票并將其發送到 Zoho Books。我設法讓重繪 令牌在很長時間后作業,現在在嘗試通過發票發送時,我收到以下回應:代碼:15 訊息:“請確保 lineItems 少于 100 個字符。”
我猜這是因為我的格式在 LineItem 部分。關于我可能做錯的任何建議。(僅供參考,我是新手,所以這對我來說很難)
這是我在控制器中的代碼:
SmsBodyInvoices smsBodyInvoices = new SmsBodyInvoices
{
//3127622000000075111
customer_id = customerIDNew,
reference_number = "Test refernce number",
date = "2013-11-17",
payment_terms = 15,
due_date = "2013-12-03",
discount = 0,
exchange_rate = 1,
lineItems = new lineItems
{
description = "test description",
item_order = 1,
bcy_rate = 1,
rate = 120,
quantity = 1,
unit = "",
discount_amount = 0,
header_name = "test header"
},
allow_partial_payments = true,
notes = "test note",
terms = "test termsn",
shipping_charge = 0,
adjustment = 0,
adjustment_description = "adjust desc",
};
var bodyNew = Newtonsoft.Json.JsonConvert.SerializeObject(smsBodyInvoices);
requestZohoInvoices.AddParameter("application / json; charset = UTF - 8", bodyNew, ParameterType.RequestBody);
IRestResponse responseZohoInvoices = clientZohoInvoices.Execute(requestZohoInvoices);
Console.WriteLine(responseZohoInvoices.Content);
Console.WriteLine(ParameterType.RequestBody);
這是模型代碼
public class SmsBodyInvoices
{
public lineItems lineItems { get; set; }
public int customer_id { get; set; }
public string reference_number { get; set; }
public string date { get; set; }
public int payment_terms { get; set; }
public string due_date { get; set; }
public int discount { get; set; }
public int exchange_rate { get; set; }
public bool allow_partial_payments { get; set; }
public string notes { get; set; }
public string terms { get; set; }
public int shipping_charge { get; set; }
public int adjustment { get; set; }
public string adjustment_description { get; set; }
}
public class lineItems
{
public tags tags { get; set; }
public string description { get; set; }
public int item_order { get; set; }
public int bcy_rate { get; set; }
public int rate { get; set; }
public int quantity { get; set; }
public string unit { get; set; }
public int discount_amount { get; set; }
public int discount { get; set; }
public string header_name { get; set; }
}
uj5u.com熱心網友回復:
“訂單項”一詞并非只有一個訂單項,而是暗示可能有多個訂單項。因此,您必須提供行專案串列。為此,請像這樣更改您的類:
public class SmsBodyInvoices
{
public IList<lineItems> line_items { get; set; } = new List<lineItems>();
// ...
}
創建資料時,添加如下行專案:
SmsBodyInvoices smsBodyInvoices = new SmsBodyInvoices
{
//3127622000000075111
customer_id = customerIDNew,
// ...
};
smsBodyInvoices.line_items.Add(new lineItems
{
description = "test description",
item_order = 1,
bcy_rate = 1,
rate = 120,
quantity = 1,
unit = "",
discount_amount = 0,
header_name = "test header"
});
var bodyNew = Newtonsoft.Json.JsonConvert.SerializeObject(smsBodyInvoices);
// ...
有關 C# 中串列和集合的詳細資訊,請參閱此鏈接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497244.html
標籤:C# json json.net 佐霍 zohobooks
下一篇:nhandled例外:NoSuchMethodError:類'_InternalLinkedHashMap<String,dynamic>'沒有實體方法'ca