2016-06-28 4 views
-4
string fc = ....... 
Dictionary<string, string> fcData = serializer.Deserialize<Dictionary<string, string>>(fc); 


if (!string.IsNullOrWhiteSpace(fcData["Diploma.GraduationBeginDate"])) 
    DateTime? GraduationBeginDate = Convert.ToDateTime(fcData["Diploma.GraduationBeginDate"]); 

エラー:{ "オブジェクト参照がオブジェクトのインスタンスに設定されていません。"}nullable DateTimeを変換するには?

これは私のコードです。 fcDataに値があり、count =11fcData["Diploma.GraduationBeginDate"]の値は10.05.2016です。なぜ機能しませんか?私たちを手伝ってくれますか ?

+5

[NullReferenceExceptionとは何ですか?それを修正するにはどうすればいいですか?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix -it) –

+0

いいえ、私は見つけることができませんでした。 –

+1

コードのより完全なセクションを '.......'なしで投稿してください。また、 - あなたは、コードをデバッグし、私の行をどの行に例外をスローしますか? –

答えて

1

DateTimeをDateTimeに影響させることはできますか? :逆で

DateTime t1 = someDate; 
DateTime? t2; 
t2 = t1; <- it works 

DateTime? t1 = someDate; 
DateTime t2; 
t2 = t1; <- won't work, you need to cast it 
t2 = (DateTime)t1; 

これが役立つことを願っています。

+0

ありがとうございます。私はこの問題を解決しました。 "GraduationBeginDate"は実際には "ディプロマです.GraduationBeginDate"これは私の間違いです。ディプロマはオブジェクトです。問題は設定する前に、私はインスタンスを取っていませんでした。もう一度あなたの助けに感謝します。 –

関連する問題