在此代码中,我将值设置为来自JSON名为myJson.code 的文件的模型类工作正常,并且值绑定到模型类没有任何问题。我的代码如下。
class Program
{
static void Main(string[] args)
{
ReadJson();
}
public static string ReadJson()
{
string case20 = "this is 20", case40 = "this is 40";
string json;
using (StreamReader r = new StreamReader(@"C:\Users\HP\Desktop\Output\myJson.json"))
{
json = r.ReadToEnd();
}
MyClass response = JsonConvert.DeserializeObject<MyClass>(json);
var dropDowns = response;
string jsonDropdown = JsonConvert.SerializeObject(dropDowns, Formatting.Indented);
return "";
}
}
这是我的模型类:
public class Customer
{
public int RATE { get; set; }
public int FEE { get; set; }
public int PERIOD { get; set; }
public string NewValue
{
get
{
var rateVal = this.RATE;
switch (rateVal)
{
case 20:
return ""; // Here, I need to get value from the ReadJson method to return (value of case20)
case 40:
return ""; // Here, I need to get value from the ReadJson method to return (value of case40)
}
return "test";
}
}
}
public class MyClass
{
public string StatusCode { get; set; }
public Customer Customer { get; set; }
public object LoanDetail { get; set; }
}
之后,我设置的值,以模型类,从Customer类我要检查的RATE,为了的价值RATE我想返回的值case20,并case40在变量值ReadJson()的方法。我如何访问这些值表单Customer类。
提前致谢!!!
千巷猫影
长风秋雁
慕盖茨4494581
相关分类