过滤C#中的JSON响应
我的JSON数据就是这样。.我想通过Duenum每月使用每月的年度Costrate。 所以我想说: Duenum值为X的数据的每月costrate值是多少?
例如; 用户提供信息:Duenum = 46 |好的,我将通过计数1.8800来计算每月的年度术
{
"dueNum": 45,
"installmentAmount": 28.89,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1300.03,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.7034,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8920,
"interestAmount": 250.01,
"fundAmount": 37.52,
"taxAmount": 12.5
},
{
"dueNum": 46,
"installmentAmount": 28.42,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1307.03,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.5604,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8800,
"interestAmount": 255.83,
"fundAmount": 38.39,
"taxAmount": 12.81
},
{
"dueNum": 47,
"installmentAmount": 27.96,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1314.22,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.4208,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8684,
"interestAmount": 261.85,
"fundAmount": 39.27,
"taxAmount": 13.1
},
,这是我的代码。我尝试了这个过程,但我会出错。 错误: “ newtonsoft.json.jsonreaderexception:'错误读取JSONREADER的jarray。当前的jsonreader项目不是数组:startObject。path。'',第1行,位置1。' “
我的代码:
string uri = "https://apis.garantibbva.com.tr:443/loans/v1/paymentPlan";
var client = new RestClient(uri);
var request = new RestRequest(Method.POST);
request.AddHeader("apikey", "l7xx8af86c14ea7e44e0ab3fbfcc6137ae09");
request.AddQueryParameter("loanType", "1");
request.AddQueryParameter("campaignCode", "BankSearch");
request.AddQueryParameter("loanAmount", "10000");
IRestResponse response = client.Execute(request);
var dueNum = 46;
double monthlyAnnualCostRate = JArray.Parse(response.Content)
.Where(p => (int)p["dueNum"]==dueNum)
.Select(p => (double)p["monthlyAnnualCostRate"])
.FirstOrDefault();
_logger.LogInformation("Garanti Bankası Response: {monthlyAnnualCostRate}", monthlyAnnualCostRate);
_logger.LogInformation("Garanti Bankası geçti");
JSON开始:
{
"data": {"list": [
{
"dueNum": 3,
"installmentAmount": 341.37,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1024.11,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 118.9411,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 9.9118,
"interestAmount": 20.08,
"fundAmount": 3.02,
"taxAmount": 1.01
},
{
"dueNum": 4,
"installmentAmount": 257.54,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1030.18,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 92.9855,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 7.7488,
"interestAmount": 25.15,
"fundAmount": 3.77,
"taxAmount": 1.26
},
My Json data is like that.. I want to take monthlyAnnualCostRate by dueNum.
So I want to say:
What is the monthlyAnnualCostRate value of the data whose dueNum value is x?
For example;
User giving info: dueNum=46 | Ok, I will calculate the monthlyAnnualCostRate by counting 1.8800
{
"dueNum": 45,
"installmentAmount": 28.89,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1300.03,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.7034,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8920,
"interestAmount": 250.01,
"fundAmount": 37.52,
"taxAmount": 12.5
},
{
"dueNum": 46,
"installmentAmount": 28.42,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1307.03,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.5604,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8800,
"interestAmount": 255.83,
"fundAmount": 38.39,
"taxAmount": 12.81
},
{
"dueNum": 47,
"installmentAmount": 27.96,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1314.22,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 22.4208,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 1.8684,
"interestAmount": 261.85,
"fundAmount": 39.27,
"taxAmount": 13.1
},
And It's my codes. I tried this process but i take error.
Error:
"Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'
"
My Codes:
string uri = "https://apis.garantibbva.com.tr:443/loans/v1/paymentPlan";
var client = new RestClient(uri);
var request = new RestRequest(Method.POST);
request.AddHeader("apikey", "l7xx8af86c14ea7e44e0ab3fbfcc6137ae09");
request.AddQueryParameter("loanType", "1");
request.AddQueryParameter("campaignCode", "BankSearch");
request.AddQueryParameter("loanAmount", "10000");
IRestResponse response = client.Execute(request);
var dueNum = 46;
double monthlyAnnualCostRate = JArray.Parse(response.Content)
.Where(p => (int)p["dueNum"]==dueNum)
.Select(p => (double)p["monthlyAnnualCostRate"])
.FirstOrDefault();
_logger.LogInformation("Garanti Bankası Response: {monthlyAnnualCostRate}", monthlyAnnualCostRate);
_logger.LogInformation("Garanti Bankası geçti");
JSON Starting:
{
"data": {"list": [
{
"dueNum": 3,
"installmentAmount": 341.37,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1024.11,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 118.9411,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 9.9118,
"interestAmount": 20.08,
"fundAmount": 3.02,
"taxAmount": 1.01
},
{
"dueNum": 4,
"installmentAmount": 257.54,
"monthlyInterestRate": 1,
"capitalAmount": 1000,
"totalInstallmentAmount": 1030.18,
"advancePaymentAmount": 0,
"expenseAmount": 100,
"annualCostRate": 92.9855,
"monthlyContractRate": 1,
"monthlyAnnualCostRate": 7.7488,
"interestAmount": 25.15,
"fundAmount": 3.77,
"taxAmount": 1.26
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作:
Try this:
您有一个JSON 对象,其中包含
data
属性,其中包含一个包含数组的list
属性。阵列不是根。因此,您需要
创建一个适当的对象模型(使用Visual Studio的“粘贴JSON作为类”),然后直接对其进行挑选,这将使事情变得容易得多。
You have a JSON object which contains a
data
property, which contains alist
property` which contains the array. The array is not the root.So you need this
Creating a proper object model (using Visual Studio's "Paste JSON as Classes") and then deserializing directly to that would make things a lot easier.