如何使用json中的Square brackeets对json进行反序列化 [英] How do I deserialise json with Square brackeets in the json

查看:75
本文介绍了如何使用json中的Square brackeets对json进行反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

paxs:[
{
type:Adult,
count:12
},
{
type:Child,
count:0
},
{
type:Infant,
计数:0
}
],







我有像这样的json的一部分,我怎样才能反序化。现在我正在使用

 JsonConvert.DeserializeObject 



来转换它但是它给了我异常,因为它是列表类型和json转换列表到这样的括号。任何帮助。谢谢

解决方案

它表示一个数组。



如果您有类似的课程:

  private   class  pax {
public string type { get ; set ;}
public int count {< span class =code-keyword> get ; set ;}
}



然后你可以反序列化为这个被称为paxs的数组:

  private   class  myObject {
public pax [] paxs { get ; set ;}
}

// ...

myObject mo = JsonConvert.DeserializeObject< myobject>(jsonString);
< / myobject >


"paxs": [
    {
      "type": "Adult",
      "count": 12
    },
    {
      "type": "Child",
      "count": 0
    },
    {
      "type": "Infant",
      "count": 0
    }
  ],




I Have part of json like this, How can I deserialize this. Now I am using

JsonConvert.DeserializeObject


to convert it but it is giving me exception because it is of list type and json convert list into brackets like that.Any help. thanks

解决方案

It denotes an array.

If you have a class like :

private class pax{
  public string type {get;set;}
  public int count {get;set;}
}


then you can deserialize to an array of this called paxs:

private class myObject{
  public pax[] paxs {get;set;}
}

//...

myObject mo = JsonConvert.DeserializeObject<myobject>(jsonString);
</myobject>


这篇关于如何使用json中的Square brackeets对json进行反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆