【问题标题】:C# Retrieve values from a Json array [duplicate]C#从Json数组中检索值[重复]
【发布时间】:2016-05-19 14:41:12
【问题描述】:

我想从我的 c# 控制器中的 Json 数组中检索值。这是我的 json 数组:

 {
    name : "Name 1", 
    description : "Description 1",
     count : 6
    }

如何在我的 c# 控制器中检索每个属性?如果我处理对象,我知道该怎么做,但这个 json 不是来自对象。

 public IList[] getList(IList[] myList)
        {
  // How to get the value of the name and the description here ?

}

【问题讨论】:

  • 完成一个简单任务的代码太多了!我最终将创建一个包含我需要的所有属性的类,然后以这种方式检索它们:myList.name、myList.description 等。

标签: c# json


【解决方案1】:

我最终将创建一个包含我需要的所有属性的类,然后以与对象相同的方式检索它们:

 CustomClass myClass ;

 string name = myClass.name
 string description = myClass.description;
 int count= myClass.count
 ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    • 2017-02-11
    • 1970-01-01
    • 2019-08-25
    • 2018-02-15
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多