Javascript C#制作Json格式

Javascript C#制作Json格式,javascript,c#,json,Javascript,C#,Json,我希望Json对象如下所示: 在C#中有以下代码: 现在我的Json是这样的: 我想要一个Json格式: //{01/21/2017,14} //{01/22/2017,17} //{01/23/2017,50} //{01/24/2017,0} //{01/25/2017,2} //{01/26/2017,0} 使用Newtonsoft.Json; 使用制度; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Thr

我希望Json对象如下所示:

在C#中有以下代码:

现在我的Json是这样的:

我想要一个Json格式:

//{01/21/2017,14}
//{01/22/2017,17}
//{01/23/2017,50}
//{01/24/2017,0}
//{01/25/2017,2}
//{01/26/2017,0}
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间TestsJson
{
类模型
{
公共日期时间日期{get;set;}
公共int单击{get;set;}
公共模型(日期时间日期,整数次点击)
{
日期=日期;
点击=点击;
}
}
班级计划
{
静态void Main(字符串[]参数)
{
变量数据=新列表()
{
新型号(新日期时间(2017,01,21),14),
新型号(新日期时间(2017,01,22),17),
新型号(新日期时间(2017年1月23日),50),
新型号(新日期时间(2017年1月24日),0),
新型号(新日期时间(2017年1月25日),2),
新型号(新日期时间(2017年1月26日),0)
};
foreach(数据中的var模型)
{
var json=“{”+JsonConvert.SerializeObject(model.Date.ToSortDateString())+”:“+model.Clicks+”}”;
Console.WriteLine(json);
}
Console.Read();
}
}
}
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间TestsJson
{
类模型
{
公共日期时间日期{get;set;}
公共int单击{get;set;}
公共模型(日期时间日期,整数次点击)
{
日期=日期;
点击=点击;
}
}
班级计划
{
静态void Main(字符串[]参数)
{
变量数据=新列表()
{
新型号(新日期时间(2017,01,21),14),
新型号(新日期时间(2017,01,22),17),
新型号(新日期时间(2017年1月23日),50),
新型号(新日期时间(2017年1月24日),0),
新型号(新日期时间(2017年1月25日),2),
新型号(新日期时间(2017年1月26日),0)
};
foreach(数据中的var模型)
{
var json=“{”+JsonConvert.SerializeObject(model.Date.ToSortDateString())+”:“+model.Clicks+”}”;
Console.WriteLine(json);
}
Console.Read();
}
}
}

您可以尝试创建字符串作为JSON对象。例如:

var list = new List<string>();
foreach (var item in stats)
     {
         list.Add(String.Format("{0},{1}",item.date.Date, item.conversions));
     }

return JsonConvert.SerializeObject(new { list });

//I haven't tested the code.
var list=newlist();
foreach(统计中的变量项)
{
Add(String.Format(“{0},{1}”,item.date.date,item.conversions));
}
返回JsonConvert.SerializeObject(新的{list});
//我还没有测试代码。

您可以尝试创建字符串作为JSON对象。例如:

var list = new List<string>();
foreach (var item in stats)
     {
         list.Add(String.Format("{0},{1}",item.date.Date, item.conversions));
     }

return JsonConvert.SerializeObject(new { list });

//I haven't tested the code.
var list=newlist();
foreach(统计中的变量项)
{
Add(String.Format(“{0},{1}”,item.date.date,item.conversions));
}
返回JsonConvert.SerializeObject(新的{list});
//我还没有测试代码。

{something,something}
不是有效的JSON格式。JSON是一个
{key:value}
对。尝试改用数组:
[“01/21/2017”,“14”]
每个日期后的“14,17,50,0,2,0”值是什么意思?@ThiagoCustodio它是指每天的内容量
{something,something}
不是有效的JSON格式。JSON是一个
{key:value}
对。试着改用数组:
[“01/21/2017”,“14”]
每个日期后的“14,17,50,0,2,0”值是什么意思?@ThiagoCustodio这是每天的量,这是非常不言自明的。这是非常不言自明的。
var list = new List<string>();
foreach (var item in stats)
     {
         list.Add(String.Format("{0},{1}",item.date.Date, item.conversions));
     }

return JsonConvert.SerializeObject(new { list });

//I haven't tested the code.