GetText() public method

public GetText ( JSONObject Input ) : string
Input JSONObject
return string
Example #1
0
 public void Save(string Path, JSONObject JSON, Format Format)
 {
     Serializer s = new Serializer();
     string text = s.GetText(JSON);
     text = s.FormatText(text, Format);
     File.WriteAllText(Path, text);
 }
Example #2
0
        public string GetText(JSONObject Input)
        {
            output = new StringBuilder();
            bool isArray = Input.ContainsOnlyObjects && Input.ChildJSONObjects.Count > 1;
            string b = isArray ? "[" : "{";
            string e = isArray ? "]" : "}";
            output.Append(b);

            foreach (JSONObject child in Input.ChildAttributes)
            {
                if (!isArray && !string.IsNullOrEmpty(child.Name))
                {
                    output.AppendFormat("\"{0}\":", child.Name);
                }

                switch (child.ValueType)
                {
                    case JSONType.String:
                        output.AppendFormat("\"{0}\"", child.Value.ToString());
                        output.Append(",");
                        break;
                    case JSONType.Number:
                    case JSONType.Raw:
                        output.AppendFormat("{0}", child.Value.ToString());
                        output.Append(",");
                        break;
                    case JSONType.Boolean:
                        output.AppendFormat("{0}", child.Value.ToString().ToLower());
                        output.Append(",");
                        break;
                    default:
                        output.AppendFormat("\"{0}\"", child.Value.ToString());
                        output.Append(",");
                        break;
                }
            }
            foreach (JSONObject child in Input.ChildJSONObjects)
            {
                if (!isArray)
                {
                    output.AppendFormat("\"{0}\":", child.Name);
                }

                Serializer s = new Serializer();
                string objecttext = s.GetText(child);
                objecttext = objecttext.TrimStart(new char[] { '\t' });
                output.AppendFormat("{0}", objecttext);
                output.Append(",");
            }

            RemoveLastComma();

            output.Append(e);
            return output.ToString();
        }
Example #3
0
 private void LoadText()
 {
     try
     {
         Serializer s = new Serializer();
         string text = s.GetText(currentObject);
         text = s.FormatText(text, format);
         CodeBox.Clear();
         CodeBox.AppendText(text);
         lastText = text;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }