Как писать c#.net кодирование для создания файла json
Любой из них, как создать файл JSon из C#.Net кодирование для нижеследующего
{"gstin":"37AAKCA3416B1Z3",
"fp":"012019",
"ГТ":0.00,
"cur_gt":0.00,
"В2В":
[{"ctin":"27AALCS1893B1Z8",
"inv":[{"inum":"AAA1819KRI0482",
"ИДТ":"03-01-2019",
"вал":13310.00,
"pos":"27",
"рчрг":"Н",
"itms":[{"num":1,
"itm_det":{"txval":11280.00,
"РТ":18,
"поддержку iAMT":2030.40,
"csamt":0.00}}],
"inv_typ":"Р"}]},
{"ctin":"33AAJCS4246C1ZM",
"inv":[{"inum":"AAA1819KRI0483",
"ИДТ":"04-01-2019",
"вал":13794.00,
"pos":"33",
"рчрг":"Н",
"itms":[{"num":1,
"itm_det":{"txval":11690.00,
"РТ":18,
"поддержку iAMT":2104.20,
"csamt":0.00}}],
"inv_typ":"Р"},
{"inum":"AAA1819KRI0484",
"ИДТ":"05-01-2019",
"вал":360.00,
"pos":"33",
"рчрг":"Н",
"itms":[{"num":1,
"itm_det":{"txval":305.00,
"РТ":18,
"поддержку iAMT":54.90,
"csamt":0.00}}],
"inv_typ":"Р"}]}
,{"ctin":"33AAECM0106G1Z6","inv":[{"inum":"AAA1819KRI0485","idt":"05-01-2019","val":531.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":450.00,"rt":18,"iamt":81.00,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0494","idt":"10-01-2019","val":46173.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":39129.00,"rt":18,"iamt":7043.22,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0495","idt":"11-01-2019","val":99027.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":83921.00,"rt":18,"iamt":15105.78,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0501","idt":"18-01-2019","val":20010.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":16958.00,"rt":18,"iamt":3052.44,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0515","idt":"28-01-2019","val":46658.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":39540.00,"rt":18,"iamt":7117.20,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0517","idt":"31-01-2019","val":13626.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":11548.00,"rt":18,"iamt":2078.64,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0518","idt":"31-01-2019","val":6818.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":5778.00,"rt":18,"iamt":1040.04,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0519","idt":"31-01-2019","val":6830.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":5788.00,"rt":18,"iamt":1041.84,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0527","idt":"31-01-2019","val":13300.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":11271.00,"rt":18,"iamt":2028.78,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAECP8284A1ZK","inv":[{"inum":"AAA1819KRI0486","idt":"05-01-2019","val":531.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":450.00,"rt":18,"iamt":81.00,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AADCT4957H2Z6","inv":[{"inum":"AAA1819KRI0487","idt":"05-01-2019","val":1782.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":1510.00,"rt":18,"iamt":271.80,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0493","idt":"09-01-2019","val":1607.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":1360.00,"rt":18,"iamt":244.80,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0523","idt":"31-01-2019","val":1719.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":1455.00,"rt":18,"iamt":261.90,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAICM4989M1ZQ","inv":[{"inum":"AAA1819KRI0488","idt":"05-01-2019","val":254.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":215.00,"rt":18,"iamt":38.70,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAJFJ8903A1ZP","inv":[{"inum":"AAA1819KRI0489","idt":"05-01-2019","val":6308.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":5345.00,"rt":18,"iamt":962.10,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0490","idt":"08-01-2019","val":14111.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":11958.00,"rt":18,"iamt":2152.44,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0496","idt":"18-01-2019","val":6835.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":5792.00,"rt":18,"iamt":1042.56,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0502","idt":"18-01-2019","val":6906.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":5853.00,"rt":18,"iamt":1053.54,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0504","idt":"22-01-2019","val":7329.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":
{"txval":6211.00,"rt":18,"iamt":1117.98,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0505","idt":"22-01-2019","val":7329.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":6211.00,"rt":18,"iamt":1117.98,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0526","idt":"31-01-2019","val":13701.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":11611.00,"rt":18,"iamt":2089.98,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"37AAECV4603R2ZR","inv":[{"inum":"AAA1819KRI0492","idt":"09-01-2019","val":25983.00,"pos":"37","rchrg":"N","itms":[{"num":1,"itm_det":
{"txval":22019.00,"rt":18,"camt":1981.71,"samt":1981.71,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"27AAQCS2565P1ZF","inv":[{"inum":"AAA1819KRI0498","idt":"18-01-2019","val":29041.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":24611.00,"rt":18,"iamt":4429.98,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0500","idt":"18-01-2019","val":14521.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":12306.00,"rt":18,"iamt":2215.08,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0514","idt":"28-01-2019","val":43533.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":36892.00,"rt":18,"iamt":6640.56,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0525","idt":"31-01-2019","val":14480.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":12271.00,"rt":18,"iamt":2208.78,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"27AAHCM3698Q1ZG","inv":[{"inum":"AAA1819KRI0503","idt":"18-01-2019","val":28106.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":23819.00,"rt":18,"iamt":4287.42,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAJCA2904R1ZG","inv":[{"inum":"AAA1819KRI0507","idt":"23-01-2019","val":12490.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":10585.00,"rt":18,"iamt":1905.30,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0510","idt":"25-01-2019","val":2360.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":2000.00,"rt":18,"iamt":360.00,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAACD0474C1ZC","inv":[{"inum":"AAA1819KRI0508","idt":"24-01-2019","val":68833.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":58333.00,"rt":18,"iamt":10499.94,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0509","idt":"24-01-2019","val":40021.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":33916.00,"rt":18,"iamt":6104.88,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"27ABACS6699B1Z3","inv":[{"inum":"AAA1819KRI0512","idt":"28-01-2019","val":10123.00,"pos":"27","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":8579.00,"rt":18,"iamt":1544.22,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AACCO6063C1ZU","inv":[{"inum":"AAA1819KRI0520","idt":"31-01-2019","val":23702.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":20087.00,"rt":18,"iamt":3615.66,"csamt":0.00}}],"inv_typ":"R"},{"inum":"AAA1819KRI0521","idt":"31-01-2019","val":23734.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":20114.00,"rt":18,"iamt":3620.52,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33CHMPS0520C1ZR","inv":[{"inum":"AAA1819KRI0522","idt":"31-01-2019","val":24426.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":20700.00,"rt":18,"iamt":3726.00,"csamt":0.00}}],"inv_typ":"R"}]},{"ctin":"33AAJFR7237B1ZE","inv":[{"inum":"AAA1819KRI0528","idt":"31-01-2019","val":43384.00,"pos":"33","rchrg":"N","itms":[{"num":1,"itm_det":{"txval":36766.00,"rt":18,"iamt":6617.88,"csamt":0.00}}],"inv_typ":"R"}]}]
,"нуль":
{"инверсия":[
{"sply_ty":"INTRB2B","expt_amt":256570.00,"nil_amt":0.00,"ngsup_amt":0.00}
,{"sply_ty":"INTRAB2B","expt_amt":84533.00,"nil_amt":0.00,"ngsup_amt":0.00}
]}
,"hsn":
{
"данные":[
{"num":1,"hsn_sc":"996521","desc":"доход от морских перевозок Non Tax","uqc":"OTH","qty":0,"val":140278.00,"txval":140278.00,"iamt":0.00,"camt":0.00,"samt":0.00,"csamt":0.00}
,{"num":2,"hsn_sc":"996799","desc":"уплотнение контейнера CHGS INCOME","uqc":"OTH","qty":0,"val":2311.62,"txval":1959.00,"iamt":157.50,"camt":97.56,"samt":97.56,"csamt":0.00}
,{"num":3,"hsn_sc":"996711","desc":"THC Charges INCOME","uqc":"OTH","qty":0,"val":504860.64,"txval":427848.00,"iamt":73772.64,"camt":1620.00,"samt":1620.00,"csamt":0.00},{"num":4,"hsn_sc":"996713","desc":"BL CHARGES INCOME","uqc":"OTH","qty":0,"val":9440.00,"txval":8000.00,"iamt":990.00,"camt":225.00,"samt":225.00,"csamt":0.00},{"num":5,"hsn_sc":"996711","desc":"MUC INCOME","uqc":"OTH","qty":0,"val":12832.50,"txval":10875.00,"iamt":1879.20,"camt":39.15,"samt":39.15,"csamt":0.00},{"num":6,"hsn_sc":"996711","desc":"IGM CHARGES","uqc":"OTH","qty":0,"val":1947.00,"txval":1650.00,"iamt":297.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":7,"hsn_sc":"996711","desc":"Handling Charges INCOME","uqc":"OTH","qty":0,"val":57761.00,"txval":48950.00,"iamt":8811.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":8,"hsn_sc":"996711","desc":"Container Storage","uqc":"OTH","qty":0,"val":8962.10,"txval":7595.00,"iamt":1367.10,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":9,"hsn_sc":"996711","desc":"Repair Cleaning Charges","uqc":"OTH","qty":0,"val":2790.70,"txval":2365.00,"iamt":425.70,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":10,"hsn_sc":"996711","desc":"SURVEY CHARGES","uqc":"OTH","qty":0,"val":5315.90,"txval":4505.00,"iamt":810.90,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":11,"hsn_sc":"996711","desc":"WASHING","uqc":"OTH","qty":0,"val":7245.20,"txval":6140.00,"iamt":1105.20,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":12,"hsn_sc":"996711","desc":"LOLO CHARGES","uqc":"OTH","qty":0,"val":7522.50,"txval":6375.00,"iamt":1147.50,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":13,"hsn_sc":"996711","desc":"IT Bond EGM Filling","uqc":"OTH","qty":0,"val":708.00,"txval":600.00,"iamt":108.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":14,"hsn_sc":"996521","desc":"Ocean Freight Slot Non Tax","uqc":"OTH","qty":0,"val":189321.00,"txval":189321.00,"iamt":0.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":15,"hsn_sc":"996711","desc":"Additional Charges Income","uqc":"OTH","qty":0,"val":40276.94,"txval":34133.00,"iamt":6143.94,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":16,"hsn_sc":"996711","desc":"SSR Charges","uqc":"OTH","qty":0,"val":1180.00,"txval":1000.00,"iamt":180.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":17,"hsn_sc":"996711","desc":"FEEDER CHARGES","uqc":"OTH","qty":0,"val":2950.00,"txval":2500.00,"iamt":450.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":18,"hsn_sc":"996719","desc":"DO CHARGES","uqc":"OTH","qty":0,"val":25960.00,"txval":22000.00,"iamt":3960.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":19,"hsn_sc":"996719","desc":"DOCUMENTATION CHARGES","uqc":"OTH","qty":0,"val":9440.00,"txval":8000.00,"iamt":1440.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":20,"hsn_sc":"996711","desc":"M R Charges Income","uqc":"OTH","qty":0,"val":13570.00,"txval":11500.00,"iamt":2070.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":21,"hsn_sc":"996711","desc":"Equipment Facilitation Charges","uqc":"OTH","qty":0,"val":11210.00,"txval":9500.00,"iamt":1710.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":22,"hsn_sc":"996711","desc":"HBL Manifest","uqc":"OTH","qty":0,"val":5900.00,"txval":5000.00,"iamt":900.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":23,"hsn_sc":"996711","desc":"CIC INCOME","uqc":"OTH","qty":0,"val":19035.76,"txval":16132.00,"iamt":2903.76,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":24,"hsn_sc":"996799","desc":"BL SURRENDER CHARGES INCOME","uqc":"OTH","qty":0,"val":2360.00,"txval":2000.00,"iamt":360.00,"camt":0.00,"samt":0.00,"csamt":0.00},{"num":25,"hsn_sc":"99","desc":"TRANSPORTATION CHARGES INCOME","uqc":"OTH","qty":0,"val":11504.00,"txval":11504.00,"iamt":0.00,"camt":0.00,"samt":0.00,"csamt":0.00}]}}
Что я уже пробовал:
Это происходит в отдельном файле класса
class Voureg { public string gstin = ""; public string fp= ""; public string gt = ""; public string cur_gt = ""; public List<b2blist> ctin { get; set; } public class b2blist { public string ctin = ""; public invlist inv { get; set; } } public class invlist { public string inum = ""; public string idt = ""; public double val = 0; public int pos = 0; public string rchrg = ""; public string inv_type = ""; } }
Это происходит в случае нажатия кнопки in
iFACTTouch.Фаформы.Voureg strjson = новые формы ФА.Воурег();
DataSet Dtclientgst = новый набор данных();
DataTable dtclienttab = новый DataTable();
dtcompgst = Лю.GetCompDetailsfrombranchid(Конвертировать.ToInt32(Session["Loginbranchid"].Метод toString()));
Dtclientgst = Лю.GetCustomergstinbranchwiseJson();
if (Dtclientgst.Таблицы.Count > 0 )
{
dtclienttab = Dtclientgst.Таблицы[0];
}
если (dtcompgst.Строк.Count > 0)
{
strjson.gstin = dtcompgst.Строки[0]["gstin"].Метод toString();
strjson.fp = "012019";
strjson.gt = "0.00";
strjson.cur_gt = "0.00";
//j.b2b = "";
если (dtclienttab.Строк.Граф > 1)
{
for (int i = 0; i < dtclienttab.Rows.Граф -1; i++)
{
if (clientgstin == "")
{
clientgstin = dtclienttab.Rows[i]["ctin"].Метод toString();
}
еще
{
clientgstin = clientgstin + "/" + dtclienttab.Rows[i]["ctin"].Метод toString();
}
}
}
string[] gstin = clientgstin.Расщеплять('/');
для (int k = 0; k < gstin.Длина; k++)
{
strjson.ctin.Добавить (gstin[k]);
}
}
строка JSONResult = Newtonsoft.Json.JsonConvert.SerializeObject(strjson);
путь к строке = @"D:\json\test.json";
если (файл.Существует(путь))
{
Файл.Удалить(путь);
using (var tw = new StreamWriter(path, true))
{
tw.WriteLine(JSONResult.Метод toString());
ТВт.Рядом();
}
}
иначе если (!файл.Существует(путь))
{
using (var tw = new StreamWriter(path, true))
{
tw.WriteLine(JSONResult.Метод toString());
ТВт.Рядом();
}
}
}
}
F-ES Sitecore
Одна вещь, которую я вижу неправильно (возможно, есть и другие), заключается в том, что
публичный список<b2blist> ctin { get; set; }
наверное, так и должно быть
публичный список<b2blist> b2b { get; set; }
поскольку это имя атрибута, содержащего Ваш массив элементов b2blist.