C#列表给JToken

时间:2014-11-20 13:44:18

标签: c# json json.net

如何在json文件中保存对象列表? 这是我的代码:

string json = System.IO.File.ReadAllText(Server.MapPath("~/settings.conf"));
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

City city = svm.City;
            jsonObj["city"]["name"] = city.Name;
            jsonObj["city"]["latitude"] = city.Latitude;
            jsonObj["city"]["longitude"] = city.Longitude;
            jsonObj["city"]["id"] = city.ID;
List<Social> bottomSocial = svm.BottomSocials;
            jsonObj["bottomSocial"] = bottomSocial;


            string output = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
            System.IO.File.WriteAllText(Server.MapPath("~/settings.conf"), output);

它适用于City,但不适用于bottomSocial。

0 个答案:

没有答案