填充Jarray中的字段

时间:2018-05-01 18:06:55

标签: c# .net json.net

我有一个像这样的json对象。我想在C#.net中的设备对象中填充sourceSerialNumber。现在我有一个动态对象,如componentConfig.Config.deviceConfig.device,但是我无法访问sourceSerialNumber字段。我怎么做到这一点?

{{
  "id": "ember10085",
  "device": [

  "contactlessEnabled": true,
  "dccTimeoutSecs": 3,
  "debitKeyIndex": 0,
  "defaultLanguage": "eng",
  "deviceType": "Ingenico iPP320 RBA",

  "googleSecrets": "",
  "lineLength": 20,

  "sourceSerialNumber": "",
  "taskDesc": "Station1",
  "terminalList": "01",
  "threadType": 1078,
  "tip": {
    "enabled": true,
    "presetMode": "Percent",
    "percent1": 15,
    "percent2": 18,
    "percent3": 0,
    "percent4": 0,
    "amount1": 20,
    "amount2": 40,
    "amount3": 0,
    "amount4": 0
     }
   }
  ]
}}

1 个答案:

答案 0 :(得分:0)

如果结构总是相同,则创建一个ValueObject类型(不是实体)来模仿它。 然后在通过Json.net反序列化响应时使用它

MyValueObject obj = JsonConvert.Convert<MyValueObject>(response) ;

Obj.propertyName = newValue;