Thursday, 3 September 2015

Error during serialization or deserialization using the JSON JavaScriptSerializer

Re: Error during serialization or deserialization using the JSON JavaScriptSerializer


You can configure the max length for json requests in your web.config file:
MaxJsonLength property is an integer so the max value you can set is: 2147483644
<configuration>
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483644"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>

Wednesday, 2 September 2015

Number to Roman convert

Number to Roman convert using Java Script
function convert(num) {

    var result = '';
    var rom = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
    var ara = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
    for (var x = 0; x < rom.length; x++) {
        while (num >= ara[x]) {
            result += rom[x];
            num -= ara[x];
        }
    }
    return result;
}

Number to Roman convert using C#
internal static string ToRoman(int number)
    {
        StringBuilder result = new StringBuilder();
        int[] digitsValues = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
        string[] romanDigits = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M" };
        while (number > 0)
        {
            for (int i = digitsValues.Count() - 1; i >= 0; i--)
                if (number / digitsValues[i] >= 1)
                {
                    number -= digitsValues[i];
                    result.Append(romanDigits[i]);
                    break;
                }
        }
        return result.ToString();
    }