Bonjour, j'ai un JSON que je voudrais afficher dans un datagridview mais j'ai une erreur qui est du je crois au sous nœud "name", j'ai bien crée mes classes pour représenter mes données mais j'ai une erreur, merci :
ERREUR :
Classe :
Code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 Public Class Utilisateur #Region "Propriétés" Public Property gender As String Public Property name As Name Public Property location As Location Public Property email As String Public Property login As Login Public Property dob As Dob Public Property registered As Registered Public Property phone As String Public Property cell As String #End Region Public Class Name Public Property title As String Public Property first As String Public Property last As String End Class ....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Dim jsonString As String = File.ReadAllText("C:\datas.json") Dim data As List(Of Utilisateur) = JsonConvert.DeserializeObject(Of List(Of Utilisateur))(jsonString) Dim bs As New BindingSource bs.DataSource = data DataGridView1.DataSource = bs
Fichier JSON :
ce code la fonctionne mais je n'arrive pas à aller chercher le "name,first" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 "utilisateurs": [ { "gender": "male", "name": { "title": "Mr", "first": "Titouan", "last": "Martinez" }, "location": { "street": { "number": 7644, "name": "Boulevard de Balmont" }, "city": "Angers", "state": "Loire", "country": "France", "postcode": 73323 }, "email": "titouan.martinez@example.com", "login": { "uuid": "fabc208b-2e53-4467-9876-91825753d1fd", "username": "lazygorilla631", "password": "lipstick", "salt": "i6umsADd", "md5": "eb7f2a59bbbd3d2b53f586ce4f10b774", "sha1": "21b3214a4b0a791eb6c5461cd0c3e106ba5d64e8", "sha256": "9dc4aaddf4073c6b84e4396b7fa21ad6c5acb3067cd636582c2fee1f9b269f0e" }, "dob": { "date": "1950-01-23T02:43:11.033Z" }, "registered": { "date": "2011-07-08T01:21:06.991Z" }, "phone": "02-43-28-09-81", "cell": "06-16-01-70-15" }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 DataGridView1.AutoGenerateColumns = False Dim FileName As String = "C:\datas.json" 'IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.json") Dim content As String = IO.File.ReadAllText(FileName) Dim results As Rootobject = JsonConvert.DeserializeObject(content, GetType(Rootobject)) Dim dataResults = results.utilisateurs.Select(Function(data) New Utilisateur With {.gender = data.gender}).ToList DataGridView1.DataSource = dataResults
Partager