c# - Write json to .txt file -
im serializing list of string json string , generating file json string reason file doesnt have "{}" of json. list serialization:
list<string> list = new list<string>(); foreach(item in model){list.add(item)} var requsers = list; var json = jsonconvert.serializeobject(requsers); system.io.file.writealltext(@"\path.txt", json);
my path.txt show this:
["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"]
but need output this:
[["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"]]
my foreach loop fil list:
(int = 1; <= 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"))); (int = 1; <= 31; i++) { var value = 0; list.add(value.tostring()); int month = item.fecha.month; if (item.fecha.day == i) { value = item.cantidad; list.add(value.tostring()); } } list.add(total.tostring()); list.add((((costo / (total + 1)) * total).tostring("c"))); }
i want each time list finish serie of foreach loop make data enclosed [] how can this?
you can wrap current object being serialized in collection serialized way want:
var json = jsonconvert.serializeobject(new list<object>() { list });
this should put "[" , "]" around current serialized text.
Comments
Post a Comment