提问人:Roasted 101 提问时间:10/31/2023 最后编辑:dbcRoasted 101 更新时间:11/4/2023 访问量:35
JSON API 响应中包含不需要的额外数组
Unwanted Extra Array Enclosed In JSON API response
问:
我想在处理输入后发送一个 JSON 响应,我将 Datatable 转换为 JSON 并发送它,但它包含在一个新数组中'd' : []
这是我的API JSON输入:
{
"region_id": "ID-10",
"document_number": "10-80/81-BIN-00005",
"industry_no": "10-CNO-0001",
"posting_date": "14-07-2080",
"customer_number": "10-CNO-0001",
"payment_for": [
{"BillType": "पानी महशुल"}
] }
这是我的 API 响应。
我不确定为什么会出现:"d"
{
"d": "[{\"CustomerNo\":\"10-CNO-0001\",\"PostingDate\":\"2023-10-31T00:00:00\",\"DocumentNo\":\"10-80/81-BIN-00005\",\"BillType\":\"5\",\"Description\":\"पानी महशुल\",\"Quantity\":0.00000,\"Rate\":0.00000,\"Amount\":1000.00,\"RegionID\":\"ID-10\",\"ExpenseID\":\"0\",\"ActivityID\":\"0\",\"SubActivityID\":\"0\",\"Dimension5ID\":\"\",\"FineAmount\":0.00,\"DiscountAmount\":-40.00,\"IsPaid\":false,\"priority\":\"2\",\"billType\":\"5\"}]"
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[AllowAnonymous]
public string InitialFetch(string region_id, string document_number, string industry_no, string posting_date, string customer_number, List<PaymentForItem> payment_for)
{
try
{
// Create a dictionary to represent the processed data
var extractedData = new Dictionary<string, object>
{
{ "region_id", region_id },
{ "document_number", document_number },
{ "industry_no", industry_no },
{ "posting_date", posting_date },
{ "customer_number", customer_number },
{ "payment_for", payment_for.Select(item => new Dictionary<string, object> { { "BillType", item.BillType } }).ToList() }
};
// Call the original GetReceivableByBillTypeFromLaravel method a datatable is extracted
DataTable receiptData = GetReceivableByBillTypeFromLaravel(extractedData);
// Serialize the response to JSON
string jsonResponse = JsonConvert.SerializeObject(receiptData);
return jsonResponse;
}
catch (Exception ex)
{
// Handle any exceptions and return an error response
return JsonConvert.SerializeObject(new { error = "Error: " + ex.Message });
}
}
上面是我处理 API 的代码。
我有另一组方法可以实际制定数据表,如果需要,我也会发布它。GetReceivableByBillTypeFromLaravel
答: 暂无答案
评论
DataTable
IEnumerable<JObject>