0
我使用Newwtonsoft.JSON
爲建立我的JSON文件,其實我所做的就是創建不同類型的模型,因爲這樣:如何使用不同的索引創建json?
class GeneralModel
{
public string Language { get; set; }
}
,然後構建JSON文件:
GeneralModel lsModel = new GeneralModel();
string json = JsonConvert.SerializeObject(lsModel);
File.WriteAllText(settingsFilePath, json);
這將創建一個包含Language
一個JSON,但我需要把這個JSON不同的類,我需要的是建立一個包含每個類名的索引,例如:
"GeneralModel": {
"Language" : "english"
},
"AnoherClassName": {
"ClassProperty" : value
}
我如何用Newtonsoft做到這一點?
您展現對象的JSON數組。嘗試完全相同的代碼 - 創建一個'對象[]'數組與您想要的類,並序列化數組而不是單個對象 –