このフォロー オブジェクトを ajax を介して asp.net Web サーバーに投稿しています。
$.ajax({
type: "POST",
url: "/home.aspx",
contentType:'application/json',
data:JSON.stringify({d1:42.00,d2:3.14,d3:'17'})
});
JSON.Net がオブジェクトを逆シリアル化するとき
JsonConvert.DeserializeObject<DataTable>(stringfied);
d2 と d3 を int として表示すると、結果は d1 = 42、d2 = 3、d3 = 17 になります。
問題はこの投稿とまったく同じです: http://digitalbush.com/2011/04/24/asp-net-mvc3-json-decimal-binding-woes/
Web フォームを使用しているため、この記事を使用してこの問題を回避できませんでした。
方法はありますか?
アップデート
実際には上記の文字列は間違っています。これは問題を反映しています。Linqpad で再現しました。
JsonConvert.DeserializeObject<DataTable>("[{\"Price\":3},{\"Price\":3.33}]").Dump();
datatable の結果: 3 と 3 ではなく 3 と 3.33
メソッドを使用DeserializeObject
すると正常に動作しますが、アプリに Datatable を MSExcel に変換する汎用関数があるため、Datatable を使用する必要があります。