Samed Ceylan
Samed Ceylan

Reputation: 5

C# Deserialize JSON

{"result":1,"message":"Client app loaded","extras":{"jobs":{"5":{"jobName":"Ford Otomobil Afi\u015fi","jobMaxIdleTime":"2060","jobMaxTime":"2040"}},"customers":{"8":"Seker LTD"}}}

public class Extras
        {
            public string loginID { get; set; }
            public string loginToken { get; set; }
            public string employeesNameSurname { get; set; }
            public string employeesLanguage { get; set; }

            public Dictionary<string, string> jobs { get; set; }
            public Dictionary<string, string> customers { get; set; }

        }

 public class Dict
        {
            public int result { get; set; }
            public string message { get; set; }
            public Extras extras { get; set; }

        }

public Dictionary jobs { get; set; } // ERROR

I can not get data from "Jobs"

Upvotes: 0

Views: 467

Answers (2)

Kunal Kapoor
Kunal Kapoor

Reputation: 768

There is a similar post regarding this. See if this is of any help to you.

Upvotes: 4

Norbert Pisz
Norbert Pisz

Reputation: 3440

    using System;
using Newtonsoft.Json;

namespace {

    [Serializable]
     class  {

        public int Result;
        public string Message;
        public Extras Extras;

        //Empty Constructor
        public (){}

        public string Serialize()
        {
            return JsonConvert.SerializeObject(this);
        }
        public static  FromJson(string json)
        {
            return JsonConvert.DeserializeObject<>(json);
        }
    }


    [Serializable]
     class 5 {

        public string JobName;
        public string JobMaxIdleTime;
        public string JobMaxTime;

        //Empty Constructor
        public 5(){}

    }


    [Serializable]
     class Jobs {

        public 5 5;

        //Empty Constructor
        public Jobs(){}

    }


    [Serializable]
     class Customers {

        public string 8;

        //Empty Constructor
        public Customers(){}

    }


    [Serializable]
     class Extras {

        public Jobs Jobs;
        public Customers Customers;

        //Empty Constructor
        public Extras(){}

    }

}

Upvotes: 1

Related Questions