public static string GetFields(string obj) { StringBuilder sb = new StringBuilder(); try { JToken jt = JToken.Parse(obj); foreach (JToken jtoken in jt) { string path = Formation.AsProperName(jtoken.Path); string typename = jtoken.Path.GetType().Name; string field = $"public {typename} {path} {{ get; set; }}"; sb.AppendLine(field); } return(sb.ToString()); } catch (Exception err) when(err is JsonReaderException || err is Exception) { return(err.Message); } }
public static string JsonString(string obj, bool Single) { StringBuilder Jsb = new StringBuilder(); try { JToken jt = JToken.Parse(obj); foreach (JToken jtoken in jt) { Jsb.AppendLine(Single ? SingleRecord(jtoken) : MultipleRecords(jtoken)); } } catch (Exception err) when(err is JsonReaderException || err is Exception) { return(err.Message); } if (Jsb.Length > 3) { Jsb.Remove(Jsb.Length - 3, 3); } string[] arr = Jsb.ToString().Split(new string[] { "\r\n", " " }, StringSplitOptions.RemoveEmptyEntries); Jsb.Clear(); foreach (var n in arr) { Jsb.Append(n); } string result = Single ? Formation.FormatJson("[{" + Jsb.ToString() + "}]") : Formation.FormatJson("[" + Jsb.ToString() + "]"); return(result); }