我怎么能从我的 json 中得到最后一个逗号:我得到这个作为输出 json
{Floor_Id:"1094",Booth_Count:12},{Floor_Id:"1095",Booth_Count:10},
这是我的 C# 代码:
StringBuilder json_result = new StringBuilder();
List<XElement> industries = ExpoHallXML.Descendants("industry").ToList();
if (industries != null && industries.Count > 0)
{
foreach (XElement industry in industries)
{
foreach (XElement floor in industry.Descendants("floor"))
{
if (floor.Attribute("id").Value != "0")
{
json_result.Append("{");
json_result.Append("Floor_Id:" + cmh.json_str(floor.Attribute("id").Value) + ",");
int booth_count = 0;
foreach (XElement page in floor.Descendants("page"))
{
booth_count = page.Descendants("booth").Count();
json_result.Append("Booth_Count:" + booth_count +"},");
}
}
}
}
}
return json_result.ToString();
求助! 谢谢
最佳答案
我认为这种方法是最好的选择。
json_result.TrimEnd(',')
关于c# - 从 C# 中的 json 中删除最后一个逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35552440/