json格式化为c#类,以集合方式处理数据

json数据:

{
  "person_num": 1,
  "person_info": [
    {
      "attributes": {
        "upper_wear_fg": {
          "score": 0.97389006614685059,
          "name": "T恤"
        },
        "cellphone": {
          "score": 0.99958902597427368,
          "name": "未使用手机"
        },
        "lower_cut": {
          "score": 0.98942846059799194,
          "name": "有下方截断"
        },
        "umbrella": {
          "score": 0.999944806098938,
          "name": "未打伞"
        },
        "orientation": {
          "score": 0.99943989515304565,
          "name": "正面"
        },
        "is_human": {
          "score": 0.96589845418930054,
          "name": "不确定"
        },
        "headwear": {
          "score": 0.99876141548156738,
          "name": "无帽"
        },
        "gender": {
          "score": 0.68398737907409668,
          "name": "男性"
        },
        "age": {
          "score": 0.60736602544784546,
          "name": "中年"
        },
        "upper_cut": {
          "score": 0.99997174739837646,
          "name": "无上方截断"
        },
        "glasses": {
          "score": 0.99150675535202026,
          "name": "无眼镜"
        },
        "lower_color": {
          "score": 0.69293707609176636,
          "name": "不确定"
        },
        "bag": {
          "score": 0.97373586893081665,
          "name": "无背包"
        },
        "upper_wear_texture": {
          "score": 0.86429083347320557,
          "name": "图案"
        },
        "smoke": {
          "score": 0.99937230348587036,
          "name": "未吸烟"
        },
        "vehicle": {
          "score": 0.99966096878051758,
          "name": "无交通工具"
        },
        "lower_wear": {
          "score": 0.98588055372238159,
          "name": "不确定"
        },
        "carrying_item": {
          "score": 0.684053897857666,
          "name": "无手提物"
        },
        "upper_wear": {
          "score": 0.99992609024047852,
          "name": "短袖"
        },
        "occlusion": {
          "score": 0.98508137464523315,
          "name": "无遮挡"
        },
        "upper_color": {
          "score": 0.99971216917037964,
          "name": "蓝"
        }
      },
      "location": {
        "height": 286,
        "width": 202,
        "top": 134,
        "score": 0.98026180267333984,
        "left": 297
      }
    },
  "log_id": 4793816596900492591
}

json格式化c#类定义:

public class Upper_wear_fg {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Cellphone {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Lower_cut {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Umbrella {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Orientation {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Is_human {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Headwear {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Gender {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Age {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Upper_cut {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Glasses {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Lower_color {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Bag {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Upper_wear_texture {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Smoke {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Vehicle {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Lower_wear {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Carrying_item {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Upper_wear {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Occlusion {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Upper_color {
	public string score  { get; set; }
	public string name  { get; set; }
}

public class Attributes {
	public Upper_wear_fg upper_wear_fg { get; set; }
	public Cellphone cellphone { get; set; }
	public Lower_cut lower_cut { get; set; }
	public Umbrella umbrella { get; set; }
	public Orientation orientation { get; set; }
	public Is_human is_human { get; set; }
	public Headwear headwear { get; set; }
	public Gender gender { get; set; }
	public Age age { get; set; }
	public Upper_cut upper_cut { get; set; }
	public Glasses glasses { get; set; }
	public Lower_color lower_color { get; set; }
	public Bag bag { get; set; }
	public Upper_wear_texture upper_wear_texture { get; set; }
	public Smoke smoke { get; set; }
	public Vehicle vehicle { get; set; }
	public Lower_wear lower_wear { get; set; }
	public Carrying_item carrying_item { get; set; }
	public Upper_wear upper_wear { get; set; }
	public Occlusion occlusion { get; set; }
	public Upper_color upper_color { get; set; }
}

public class Location {
	public string height  { get; set; }
	public string width  { get; set; }
	public string top  { get; set; }
	public string score  { get; set; }
	public string left  { get; set; }
}

public class Person_info {
	public Attributes attributes { get; set; }
	public Location location { get; set; }
}

public class RootObject {
	public string person_num  { get; set; }
	public List person_info { get; set; }
	public string log_id  { get; set; }
}

json数据处理:

RootObject rb = JsonConvert.DeserializeObject(result);
List person_info = rb.person_info;

最后以集合的方式访问即可。

你可能感兴趣的:(json格式化为c#类,以集合方式处理数据)