none
Json to object[] RRS feed

  • Question

  • is it possible to convert json 
    ["2010-01-03T00:00:00","2010-01-10T00:00:00"]

     

     to 

    object[] of type Datetime because I this code below to call stored procedures dynamically?


    object [] Params = (object [])JsonConvert.DeserializeObject(JSON, typeof (object []));
    Type currType = context.GetType();
    MethodInfo currMethod = currType.GetMethod(StoredProcedureName);
    var SPResults = currMethod.Invoke(context, Params);

    When it hits the invoke line, it fails giving me this: Object of type 'System.String' cannot be converted to type 'System.Nullable`1[System.DateTime]'.

    Any ideas on how to tackle this problem?

    Thanks

    Tuesday, January 5, 2010 6:17 PM

Answers

  • DateTime?[] dates = Params.Select(d => {
        if(!string.IsNullOrEmpty(d))
        {
            DateTime dt;
            if(DateTime.TryParse(d, out dt))
                return dt;
        }
        return (DateTime?)null;
    }).ToArray();
    • Marked as answer by Bin-ze Zhao Friday, January 8, 2010 6:36 AM
    Wednesday, January 6, 2010 10:10 AM