private JArray GetInnerTable(List <JsonTable> innerTables, string innerTableName) { JsonTable table = innerTables.FirstOrDefault(t => t.tableName.ToLower().Equals(innerTableName.ToLower())); if (table != null) { return(JArray.Parse(JsonConvert.SerializeObject(table.values))); } return(new JArray()); }
public JArray GetTableJson(Type table, JArray array, string tableName) { List <JsonTable> tables = array.ToObject <List <JsonTable> > (); JsonTable desireTable = tables.FirstOrDefault(t => t.tableName.ToLower().Equals(tableName.ToLower())); if (desireTable != null) { Dictionary <string, string> innerTableMap = new Dictionary <string, string> (); foreach (PropertyInfo property in table.GetProperties()) { string innerTableName = GetInnerTableName(property); if (innerTableName != null) { innerTableMap.Add(property.Name, innerTableName); } else { continue; } } if (innerTableMap.Count() > 0) { JArray tableArray = new JArray(); foreach (JObject json in JArray.Parse(JsonConvert.SerializeObject(desireTable.values))) { List <JsonTable> innertableList = JArray.Parse(json.GetValue(nameof(innerTables)).ToString()).ToObject <List <JsonTable> > (); foreach (var key in innerTableMap.Keys) { json[key] = GetInnerTable(innertableList, innerTableMap.GetValueOrDefault(key)); } tableArray.Add(json); } return(tableArray); } else { var values = JsonConvert.SerializeObject(desireTable.values); return(JArray.Parse(values)); } } else { return(new JArray()); } }