リストをシリアル化し、特定の方法でファイルに書き込みたいのですが、今はできません。ファイルは次のようになります。
["ENS FRUTAS",
"REST",
"CENAS",
"$26.50","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0",
"1",
"$26.50"]
しかし、私はこのようにそれが必要です
[
{
"Descripcion": "ENS FRUTAS","Pdv": "REST","Rid": "CENAS","PV": "$26.50","1": "0",
"2": "1","3": "0","4": "0","5": "1","6": "0","7": "0","8": "1","9": "0","10": "0",
"11": "1","12": "0","13": "0","14": "1","15": "0","16": "0","17": "1","18": "0",
"19": "0","20": "1","21": "0","22": "0","23": "1","24": "0","25": "0","26": "1",
"27": "0","28": "0","29": "0","30": "1","31": "0","Total": "1","Venta": "$26.50",
}]
ファイルを 2 番目の形式のようにするにはどうすればよいですか? これは私のシリアライズされたアクションです:
List<object> list = new List<object>();
foreach (var item in db.Pos)
{
var total = 0;
decimal costo = 0;
for (int i = 1; i <= 31; i++)
{
var value = 0;
if (item.Fecha.Day == i) { value = item.Cantidad; costo = costo + item.Total; }
total += value;
}
list.Add(item.Descripcion);
list.Add(item.Pdv);
list.Add(item.Rid);
list.Add(((costo / (total + 1)).ToString("C")));
for (int i = 1; i <= 31; i++)
{
var value = 0;
list.Add(value);
int month = item.Fecha.Month;
if (item.Fecha.Day == i) { value = item.Cantidad; list.Add(value); }
}
list.Add(total);
list.Add((((costo / (total + 1)) * total).ToString("C")));
}
var javaScriptSerializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
string jsonString = javaScriptSerializer.Serialize(list);
System.IO.File.WriteAllText(@"C:\path.txt", jsonString);