using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestsJson
{
class Model
{
public DateTime Date { get; set; }
public int Clicks { get; set; }
public Model(DateTime date, int clicks)
{
Date = date;
Clicks = clicks;
}
}
class Program
{
static void Main(string[] args)
{
var data = new List<Model>()
{
new Model(new DateTime(2017, 01, 21), 14),
new Model(new DateTime(2017, 01, 22), 17),
new Model(new DateTime(2017, 01, 23), 50),
new Model(new DateTime(2017, 01, 24), 0),
new Model(new DateTime(2017, 01, 25), 2),
new Model(new DateTime(2017, 01, 26), 0)
};
foreach (var model in data)
{
var json = "{" + JsonConvert.SerializeObject(model.Date.ToShortDateString()) + ":" + model.Clicks + "}";
Console.WriteLine(json);
}
Console.Read();
}
}
}
'{something,something}'不是有效的JSON格式。 JSON是一個'{key:value}'對。嘗試用數組代替:'[「01/21/2017」,「14」]' – Rajesh
什麼意思是每個日期後的「14,17,50,0,2,0」值? –
@ThiagoCustodio這是每天的東西數量 – mohammad