IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Dotnet Discussion :

c# Désérialisé un fiché Json et convertir en Array


Sujet :

Dotnet

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut c# Désérialisé un fiché Json et convertir en Array
    Bonjour a tous ,

    me re voila encode avec un petit soucis , j'arrive pas a convertir un fiché json en Array .

    voila ce que contient le fiché :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    {"CalendarDatesOnViewChange":"[{\"Id\":9132012,\"Date\":\"01/05/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"AmVyW/BW9VjkePkixCwEtw==\",\"AllocationIdInInt\":9132012,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"7/Z+oc6cKuvsx1jOrogieQ==\",\"AllocationIdInInt\":9132017,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"SXpwkCdBva3tdATqlZzL4g==\",\"AllocationIdInInt\":9132018,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"24vXXm1yB1AhnpJrCDaJRQ==\",\"AllocationIdInInt\":9132019,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132013,\"Date\":\"01/06/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"tm+gL+JsbwHKl+xshS7zww==\",\"AllocationIdInInt\":9132013,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"+hUeFAgh41Nu0Yzoh9Gzrg==\",\"AllocationIdInInt\":9132020,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"0adBB96zUGyCQrIFKFFQmQ==\",\"AllocationIdInInt\":9132021,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"0Ub/qgxeVtzYNjSn55dnuw==\",\"AllocationIdInInt\":9132022,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132014,\"Date\":\"01/07/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"J1rHMMeOblb+2+QVul1JyA==\",\"AllocationIdInInt\":9132014,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"dv7NRB5I7avwavkJy21+uw==\",\"AllocationIdInInt\":9132023,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"vW7iXnllJ42gbFIHgC4Daw==\",\"AllocationIdInInt\":9132024,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"fP0XrZw5QtTIfkP7mCcm2A==\",\"AllocationIdInInt\":9132025,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132015,\"Date\":\"01/08/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"imF5wbjmHlGDgyR2z+QNpg==\",\"AllocationIdInInt\":9132015,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"y9u7PLDClz++TSg98eeVLg==\",\"AllocationIdInInt\":9132026,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"lB4mAWHBX0gbJ7NE0ltuYQ==\",\"AllocationIdInInt\":9132027,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"Rwm+iJSHuhdiEzbIjz0Smg==\",\"AllocationIdInInt\":9132028,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132016,\"Date\":\"01/09/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"ybac4DbF7RCYqyX0yRI4Vw==\",\"AllocationIdInInt\":9132016,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"Q0heXQGZCQOFI9wgCCsw6g==\",\"AllocationIdInInt\":9132029,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"OZNJwgeIDoVL4l+g4E6tdA==\",\"AllocationIdInInt\":9132030,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"KKlIn1ICRzEJ43UHCr6SMA==\",\"AllocationIdInInt\":9132031,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132032,\"Date\":\"01/13/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"fBaQbjaMZ2R7s0QGGJoeAQ==\",\"AllocationIdInInt\":9132041,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"UQA6yjI0j/0UTboY77mogg==\",\"AllocationIdInInt\":9132032,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"qnJnoYsXRj6gZQk/dNACbA==\",\"AllocationIdInInt\":9132033,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"a2JwXpGvq1gd+X1dZo1rAQ==\",\"AllocationIdInInt\":9132034,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132035,\"Date\":\"01/14/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"7lX/KSXb4I4rcZnaes5HnQ==\",\"AllocationIdInInt\":9132042,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"6qYhDK1JNdNIckW2moPgYg==\",\"AllocationIdInInt\":9132035,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"S1GKkn0PYn82hhuDxjlQMQ==\",\"AllocationIdInInt\":9132036,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"VpGQZj/gY0AeP/mXlZr3rA==\",\"AllocationIdInInt\":9132037,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":9132038,\"Date\":\"01/15/2020\",\"IsHoliday\":false,\"IsWeekend\":false,\"TimeBands\":[{\"Id\":19979,\"StartTime\":\"8:30\",\"EndTime\":\"9:30\",\"RemainingSlots\":8,\"AllocationId\":\"9X6kGmbD2QUu6qJ96vM8Fg==\",\"AllocationIdInInt\":9132043,\"EndTicks\":342000000000},{\"Id\":19980,\"StartTime\":\"9:30\",\"EndTime\":\"10:30\",\"RemainingSlots\":9,\"AllocationId\":\"tbz3VB/wO33IVt5wgntOYA==\",\"AllocationIdInInt\":9132038,\"EndTicks\":378000000000},{\"Id\":19981,\"StartTime\":\"10:30\",\"EndTime\":\"11:30\",\"RemainingSlots\":9,\"AllocationId\":\"AC3BOeVi3r0PiEg2Bd6yiQ==\",\"AllocationIdInInt\":9132039,\"EndTicks\":414000000000},{\"Id\":19982,\"StartTime\":\"11:30\",\"EndTime\":\"12:30\",\"RemainingSlots\":9,\"AllocationId\":\"/I8KLy9M+hP9sGP+NNh7Zg==\",\"AllocationIdInInt\":9132040,\"EndTicks\":450000000000}],\"TimeBandsTable\":null},{\"Id\":2162917,\"Date\":\"01/02/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162918,\"Date\":\"01/03/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162924,\"Date\":\"01/04/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162919,\"Date\":\"01/10/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162925,\"Date\":\"01/11/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162920,\"Date\":\"01/17/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162926,\"Date\":\"01/18/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162921,\"Date\":\"01/24/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162927,\"Date\":\"01/25/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162922,\"Date\":\"01/31/2020\",\"IsHoliday\":true,\"IsWeekend\":false,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162928,\"Date\":\"02/01/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162929,\"Date\":\"02/08/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162930,\"Date\":\"02/15/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162931,\"Date\":\"02/22/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162932,\"Date\":\"02/29/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162933,\"Date\":\"03/07/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162934,\"Date\":\"03/14/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162935,\"Date\":\"03/21/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162936,\"Date\":\"03/28/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162937,\"Date\":\"04/04/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162938,\"Date\":\"04/11/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162939,\"Date\":\"04/18/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162940,\"Date\":\"04/25/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162941,\"Date\":\"05/02/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162942,\"Date\":\"05/09/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162943,\"Date\":\"05/16/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162944,\"Date\":\"05/23/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162945,\"Date\":\"05/30/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162946,\"Date\":\"06/06/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162947,\"Date\":\"06/13/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162948,\"Date\":\"06/20/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162949,\"Date\":\"06/27/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162950,\"Date\":\"07/04/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162951,\"Date\":\"07/11/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162952,\"Date\":\"07/18/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162953,\"Date\":\"07/25/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162954,\"Date\":\"08/01/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162955,\"Date\":\"08/08/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162956,\"Date\":\"08/15/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162957,\"Date\":\"08/22/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162958,\"Date\":\"08/29/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162959,\"Date\":\"09/05/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162960,\"Date\":\"09/12/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162961,\"Date\":\"09/19/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162962,\"Date\":\"09/26/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162963,\"Date\":\"10/03/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162964,\"Date\":\"10/10/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162965,\"Date\":\"10/17/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162966,\"Date\":\"10/24/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162967,\"Date\":\"10/31/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162968,\"Date\":\"11/07/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162969,\"Date\":\"11/14/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162970,\"Date\":\"11/21/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162971,\"Date\":\"11/28/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162972,\"Date\":\"12/05/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162973,\"Date\":\"12/12/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162974,\"Date\":\"12/19/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null},{\"Id\":2162975,\"Date\":\"12/26/2020\",\"IsHoliday\":true,\"IsWeekend\":true,\"TimeBands\":[],\"TimeBandsTable\":null}]","isRedirect":false,"appointmentAlreadyBlocked":null,"appointmentBookingType":null,"appointmentActionType":1}
    voila mon 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
    20
    using Newtonsoft.Json;
    using System;
    using System.IO;
     
    namespace TestJson
    {
        class Program
        {
            static void Main(string[] args)
            {
     
                StreamReader reader = new StreamReader("D:\\test\\myfile.txt");
                JsonTextReader tab = new JsonTextReader(reader);
                JsonSerializer js = new JsonSerializer();
                var test = js.Deserialize(tab);
     
                Console.WriteLine(test);
            }
        }
    }
    j'attend vos réponse avec impatience .
    Merci d'avance .

  2. #2
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut
    Re-Bonjour,

    Aujourd'hui j ai reussi a faire un pas .

    j'ai créer une class avec les propriétés qui se trouve dans mon fiché Json.

    voila la classe .

    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
    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace TestJson
    {
        public class Calendar
        {
            public string CalendarDatesOnViewChange { get; set; }
            public bool isRedirect { get; set; }
            public string appointmentAlreadyBlocked { get; set; }
            public string appointmentBookingType { get; set; }
            public int appointmentActionType { get; set; }
     
        }
    }

    aprés désérialiser le fiché je dois encore désérialisé la propriété CalendarDatesOnViewChange .

    alors j'ai fais sa dans mon 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
    20
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System;
    using System.Collections.Generic;
    using System.IO;
     
    namespace TestJson
    {
        class Program
        {
            static void Main(string[] args)
            {
     
                string json = System.IO.File.ReadAllText("D:\\test\\myfile.txt");
                var calendrier = Newtonsoft.Json.JsonConvert.DeserializeObject<Calendar>(json);
                Console.WriteLine(calendrier.CalendarDatesOnViewChange);
     
            }
        }
    }
    et j'ai eu ce résultat

    Nom : test.png
Affichages : 187
Taille : 281,2 Ko

    alors la je bloque parceque j'arrive pas a manupilé ce string : calendrier.CalendarDatesOnViewChange
    je vois que dedans il ya encore des jsons .
    j'aimerais manupiler ce string pour extraire une valeur aléatoir de "AllocationId":"0adBB96zUGyCQrIFKFFQmQ==" .

    j'attend toujous vos réponse et merci a tous .

  3. #3
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 674
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 674
    Points : 5 259
    Points
    5 259
    Par défaut
    Tu as du JSON qui contient du JSON.
    Ce qui fait que ce que tu récupères dans la chaine CalendarDatesOnViewChange est également du JSON.
    Il faut donc déserialiser le contenu de CalendarDatesOnViewChange

    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
     
         public class TimeBand    {
            public int Id { get; set; } 
            public string StartTime { get; set; } 
            public string EndTime { get; set; } 
            public int RemainingSlots { get; set; } 
            public string AllocationId { get; set; } 
            public int AllocationIdInInt { get; set; } 
            public object EndTicks { get; set; } 
        }
     
        public class CalendarDatesOnViewChangeArrayItem    {
            public int Id { get; set; } 
            public string Date { get; set; } 
            public bool IsHoliday { get; set; } 
            public bool IsWeekend { get; set; } 
            public List<TimeBand> TimeBands { get; set; } 
            public object TimeBandsTable { get; set; } 
        }
     
        public class CalendarDatesOnViewChangeArray {
            public List<CalendarDatesOnViewChangeArrayItem> CalendarDatesOnViewChange { get; set; } 
        }

  4. #4
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut
    Re-Bonjour,
    Quand je Désérialize la Chaine CalendarOnViewChanges , Je la sérialise en json pour l'affiché en console .
    Alors je recois un Json avec Plein de CalendarOnviewChanges avec une Valeur NULL .
    voila mon code .
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
                var json = File.ReadAllText("D:\\test\\myfile.txt");
                var c1 = JsonConvert.DeserializeObject<Calendar>(json);
                var c2 = JsonConvert.DeserializeObject<List<CalendarDatesOnViewChangeArray>>(c1.CalendarDatesOnViewChange);
                var c2tojson = Newtonsoft.Json.JsonConvert.SerializeObject(c2);
     
                Console.WriteLine(c2tojson);
    voila une capture .

    Nom : Untitled.png
Affichages : 177
Taille : 229,8 Ko

    Merci énormément de votre aide .

  5. #5
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut
    Merci Beaucoup @POPO .
    Désolé pour le commentaire précedent j'étais moin concentré .
    Enfin j'ai réuissi a le Désérialisé et avoir un Json plus simple .

    Voila le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
                var json = File.ReadAllText("D:\\test\\jsontxt");
                var c1 = JsonConvert.DeserializeObject<Calendar>(json);
                var c2 = JsonConvert.DeserializeObject<List<CalendarDatesOnViewChangeArrayItem>>(c1.CalendarDatesOnViewChange);
                var c2tojson = Newtonsoft.Json.JsonConvert.SerializeObject(c2[0].TimeBands);
     
                Console.WriteLine(c2tojson);
    Voila une Image :
    Nom : Untitled.png
Affichages : 160
Taille : 183,0 Ko

    es que vous pouver m'aider a faire un Link Query pour avoir just les TIMEBANDS qui ont des donnés et pas qui sont vide ?

    Merci POPO

  6. #6
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut
    Re-Bonjour,

    j'ai fais cette Link Query et j'ai Réuissi juste a avoir tous le premier tableaux qui contien un TimeBands Non null,

    du coup j'aimerais récupéré tous les tableaux qui contiennent un TimeBands Non Null ,

    voila le 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
            static void Main(string[] args)
            {
     
                var json = File.ReadAllText("D:\\test\\json.txt");
                var c1 = JsonConvert.DeserializeObject<Calendar>(json);
                var c2 = JsonConvert.DeserializeObject<List<CalendarDatesOnViewChangeArrayItem>>(c1.CalendarDatesOnViewChange);
                var c2tojson = Newtonsoft.Json.JsonConvert.SerializeObject(c2,Formatting.Indented);
                JArray co = JArray.Parse(c2tojson);
                var MyList = (from s in co
                                   select s["TimeBands"]).ToList();
                var mlist = co.FirstOrDefault(s => !string.IsNullOrEmpty(s["TimeBands"].ToString()));
     
                Console.WriteLine(mlist);
     
            }
    et la j'ai récupéré sa :

    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
    {
      "Id": 9132012,
      "Date": "01/05/2020",
      "IsHoliday": false,
      "IsWeekend": false,
      "TimeBands": [
        {
          "Id": 19979,
          "StartTime": "8:30",
          "EndTime": "9:30",
          "RemainingSlots": 8,
          "AllocationId": "AmVyW/BW9VjkePkixCwEtw==",
          "AllocationIdInInt": 9132012,
          "EndTicks": 342000000000
        },
        {
          "Id": 19980,
          "StartTime": "9:30",
          "EndTime": "10:30",
          "RemainingSlots": 9,
          "AllocationId": "7/Z+oc6cKuvsx1jOrogieQ==",
          "AllocationIdInInt": 9132017,
          "EndTicks": 378000000000
        },
        {
          "Id": 19981,
          "StartTime": "10:30",
          "EndTime": "11:30",
          "RemainingSlots": 9,
          "AllocationId": "SXpwkCdBva3tdATqlZzL4g==",
          "AllocationIdInInt": 9132018,
          "EndTicks": 414000000000
        },
        {
          "Id": 19982,
          "StartTime": "11:30",
          "EndTime": "12:30",
          "RemainingSlots": 9,
          "AllocationId": "24vXXm1yB1AhnpJrCDaJRQ==",
          "AllocationIdInInt": 9132019,
          "EndTicks": 450000000000
        }
      ],
      "TimeBandsTable": null
    }
    et encore Merci POPO , j'attend votre réponse .

  7. #7
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 674
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 674
    Points : 5 259
    Points
    5 259
    Par défaut
    Bonjour,

    Désolé ne n'être pas revenu plus tôt.
    Tu n'obtiens qu'un seul enregistrement à cause du FirstOrDefault.
    Si tu veux tous les enregistrement ou TimeBand n'est pas null il faut utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    co.Where(s => !string.IsNullOrEmpty(s["TimeBands"].ToString())).ToList();

  8. #8
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    89
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2018
    Messages : 89
    Points : 85
    Points
    85
    Par défaut
    Citation Envoyé par popo Voir le message
    Bonjour,

    Désolé ne n'être pas revenu plus tôt.
    Tu n'obtiens qu'un seul enregistrement à cause du FirstOrDefault.
    Si tu veux tous les enregistrement ou TimeBand n'est pas null il faut utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    co.Where(s => !string.IsNullOrEmpty(s["TimeBands"].ToString())).ToList();

    Merci Popo , le problème est résolu .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. script php pour convertir un array en xml
    Par omar24 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 02/03/2011, 14h22
  2. Récupérer les données d'un Datagrid et les convertir en Array
    Par Invité dans le forum ActionScript 3
    Réponses: 3
    Dernier message: 22/12/2010, 21h13
  3. Convertir Cell array en Double array
    Par anouaraz dans le forum MATLAB
    Réponses: 6
    Dernier message: 27/05/2010, 16h46
  4. [JSON] Problème de Cast Array en String
    Par helter_skelter dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 21/10/2009, 12h02
  5. Convertir un array<Byte>^ en unsigned char*
    Par xxiemeciel dans le forum C++/CLI
    Réponses: 5
    Dernier message: 12/06/2007, 20h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo