ルート要素「users」と「user」アイテムのリストを含むJSONファイルを受け取りました。
List
jsonをと呼ばれるカスタムクラスのに逆シリアル化しようとしていますが、それをカバーできないUser
という、を取得し続けます。JsonSerializationException
私は次のことを試しました:
コード:
public class User
{
public int ID { get; set; }
public bool Active { get; set; }
public string Name { get; set; }
}
public class Response
{
public List<User> Users { get; set; }
public JObject Exception { get; set; }
}
と -
public Response DeserializeJSON(string json)
{
Response deserialized = JsonConvert.DeserializeObject<Response>(json);
return deserialized;
}
JSON:
{
"Users": {
"User": [
{
"id": "1",
"active": "true",
"name": "Avi"
},
{
"id": "2",
"active": "false",
"name": "Shira"
},
{
"id": "3",
"active": "false",
"name": "Moshe"
},
{
"id": "4",
"active": "false",
"name": "Kobi"
},
{
"id": "5",
"active": "true",
"name": "Yael"
}
]
}
}
スタイリング不良でごめんなさい!!