コード例 #1
0
        private JsonData GetInformation(string json)
        {
            try
            {
                Dictionary <string, string> map = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
                JsonData jData = new JsonData();
                if (map != null)
                {
                    if (map.ContainsKey("id") && map.ContainsKey("data"))
                    {
                        int     id   = -1;
                        dynamic data = JsonConvert.DeserializeObject(map["data"]);
                        if (int.TryParse(map["id"], out id))
                        {
                            jData.id = id;
                        }

                        TotalFacilitiesRequired total = GetTotalFacilitiesRequired(map["data"]);
                        jData.minimumfixture = total;

                        return(jData);
                    }
                }
                return(null);
            }
            catch
            {
                return(null);
            }
        }
コード例 #2
0
        private TotalFacilitiesRequired GetTotalFacilitiesRequired(string dataStr)
        {
            TotalFacilitiesRequired total = new TotalFacilitiesRequired();

            if (!string.IsNullOrEmpty(dataStr))
            {
                dynamic data = JsonConvert.DeserializeObject(dataStr);
                if (data != null)
                {
                    if (data.fixtureUnitArray != null)
                    {
                        total.fixtureUnitArray = GetFixtureUnitArray(data);
                    }
                    if (data.outItem != null)
                    {
                        total.outItem = JsonConvert.DeserializeObject <string>((string)data.outItem);
                    }
                    if (data.isEditing != null)
                    {
                        total.isEditing = (bool)data.isEditing;
                    }

                    if (data.totalRequiredFixture != null)
                    {
                        total.totalRequiredFixture = new Dictionary <string, double>();
                        var temp = data.totalRequiredFixture;
                        foreach (var i in temp)
                        {
                            string key   = i.Name;
                            double value = i.Value;
                            total.totalRequiredFixture.Add(key, value);
                        }
                    }

                    if (data.totalFixtureBasedOnGender != null)
                    {
                        //This is the worst way to decode json.
                        total.totalFixtureBasedOnGender = new Dictionary <string, double>();
                        var temp = data.totalFixtureBasedOnGender;
                        foreach (var i in temp)
                        {
                            string key   = i.Name;
                            double value = i.Value;
                            total.totalFixtureBasedOnGender.Add(key, value);
                        }
                    }
                    if (data.femaleWaterClosetAddIn != null)
                    {
                        total.femaleWaterClosetAddIn = JsonConvert.DeserializeObject <double>((string)data.femaleWaterClosetAddIn);
                    }
                    if (data.maleUrinalsAllowedToBeAdded != null)
                    {
                        total.maleUrinalsAllowedToBeAdded = JsonConvert.DeserializeObject <double>((string)data.maleUrinalsAllowedToBeAdded);
                    }
                    if (data.userUrinalsAdded != null)
                    {
                        total.userUrinalsAdded = JsonConvert.DeserializeObject <double>((string)data.userUrinalsAdded);
                    }
                    if (data.sliderValue != null)
                    {
                        total.sliderValue = JsonConvert.DeserializeObject <int>((string)data.sliderValue);
                    }
                }
                return(total);
            }
            return(null);
        }