E
engahmedbarbary
Guest
- 300
- 11.2Problem
I work on newton soft library and I try to insert data to table master_table
but my pro
- insert into master_table(id,branch_id,name,address,phone) values (1,1,"bar","fleet street","555")
my jsonfile D:\\1.json as below :
- {
- "master" : {
- "table": "master_table",
- "fields": {
- "name" : "bar",
- "address" : "fleet street",
- "phone" : "555"
- },
- "keys":{
- "id" : 1,
- "branch_id" : 1
- }
- }
- }
insert statement as result .
How to concatenate insert statement that have keys + fields
as statement on first thread .
what i have tried
public static ExpandoObject ToExpando(string json)
{
if (string.IsNullOrEmpty(json))
return null;
return (ExpandoObject)ToExpandoObject(JToken.Parse(json));
}
private static object ToExpandoObject(JToken token)
{
switch (token.Type)
{
case JTokenType.Object:
var expando = new ExpandoObject();
var expandoDic = (IDictionary<string, object>)expando;
foreach (var prop in token.Children<JProperty>())
expandoDic.Add(prop.Name, ToExpandoObject(prop.Value));
return expando;
case JTokenType.Array:
return token.Select(ToExpandoObject).ToList();
default:
return ((JValue)token).Value;
}
}
static void Main(string[] args)
{
string JsonData = File.ReadAllText("D:\\1.json");
var ebj = SqlFactory.ToExpando (JsonData);
var name = (ebj as dynamic).master.table;
var fields = (ebj as dynamic).master.fields;
foreach (dynamic i in fields)
{
string key = i.Key;
object value = i.Value;
}
var keys = (ebj as dynamic).master.keys;
// i need after that create function return create insert statement
}
Continue reading...