Ejemplo n.º 1
0
        public static string ToJSON(string input)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{ ");
            int len = GMSDSMaps.ComputeStringLength(input.Substring(8, 8));

            input = input.Remove(0, 16);
            Queue <string> keys   = new Queue <string>(len);
            Queue <string> values = new Queue <string>(len);

            for (int i = 0; i < len; i++)
            {
                int keylen = GMSDSMaps.ComputeStringLength(input.Substring(24, 8));
                keys.Enqueue("\"" + GMSWeird.GMSstringtoJSON(input.Substring(32, 2 * keylen)) + "\"");
                input = input.Remove(0, (keylen * 2) + 32);
            }
            for (int i = 0; i < len; i++)
            {
                switch (input.Substring(0, 8))
                {
                case "00000000":
                    values.Enqueue(GMSDSMaps.GMSdoubletoJSON(input.Substring(8, 16)));
                    input = input.Remove(0, 32);
                    break;

                case "01000000":
                    int    stringlen = 2 * GMSDSMaps.ComputeStringLength(input.Substring(24, 8));
                    string str       = GMSWeird.GMSstringtoJSON(input.Substring(32, stringlen));
                    values.Enqueue("\"" + str + "\"");
                    input = input.Remove(0, 32 + stringlen);
                    break;

                default:
                    throw new InvalidDataException("Unknown datatype, please go bug the dev.");
                }
            }
            for (int i = 0; i < len; i++)
            {
                sb.Append(keys.Dequeue() + ": " + values.Dequeue() + ", ");
            }
            sb.Remove(sb.Length - 2, 2);
            string result = sb.ToString();

            return(result + " }");
        }
Ejemplo n.º 2
0
        public static string ToJSON(string input)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(input.Substring(0, 8) + "{ ");
            input = input.Remove(0, 16);
            while (input.Length > 0)
            {
                input = input.Remove(0, 8);
                int keylen = ComputeStringLength(input.Substring(0, 8));
                input = input.Remove(0, 8);
                sb.Append("\"" + GMSWeird.GMSstringtoJSON(input.Substring(0, 2 * keylen)) + "\": ");
                input = input.Remove(0, keylen * 2);
                switch (input.Substring(0, 8))
                {
                case "00000000":
                    sb.Append(GMSdoubletoJSON(input.Substring(8, 16)));
                    input = input.Remove(0, 24);
                    break;

                case "0D000000":
                    sb.Append((GMSdoubletoJSON(input.Substring(8, 16)) == "1.000000") ? "true" : "false");
                    input.Remove(0, 24);
                    break;

                case "01000000":
                    int    stringlen = 2 * ComputeStringLength(input.Substring(8, 8));
                    string str       = GMSWeird.GMSstringtoJSON(input.Substring(16, stringlen));
                    sb.Append("\"" + str + "\"");
                    input = input.Remove(0, 16 + stringlen);
                    break;

                default:
                    throw new InvalidDataException("Unknown datatype, please go bug the dev.");
                }
                sb.Append(", ");
            }
            sb.Remove(sb.Length - 2, 2);
            string result = sb.ToString();

            return(result + " }");
        }