c# - 从 C# 中的 json 中删除最后一个逗号?

标签 c#

我怎么能从我的 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/

相关文章:

c# - 如何在 C# 中将 Cobol COMP 字段输出转换为可读十进制?

c# - 为什么 XAML 不等同于 AddHandler?

c# - 二维数组的所有可能组合

c# - C#4.0中如何调用动态类型的静态方法?

c# - Xamarin.Forms - 将值从 View 传递到 ViewModel

c# - Visual Studio Web 测试请求

c# - Dapper 反序列化 XML

c# - linq 排序 OrderBy(a => a.Url) 中的 System.NullReferenceException,UWP

c# - 显示自定义层次结构

c# - 将窗口停靠在另一个窗口中