小编joe*_*hen的帖子

将根元素添加到 json

我正在使用 NewtosoftJson 生成 json 字符串,并使用表来格式化 json。这是一个简单的键值对列表,如下所示:

public class items
{
    private string key = String.Empty;
    private string value = String.Empty;
    public string Key
    {
        get
        {
            return key;
        }
        set
        {
            if (value != key)
            {
                key = value;                  
            }
        }
    }
    public string Value
    {
        get
        {
            return value;
        }
        set
        {
            if (value != this.value)
            {
                this.value = value;                  
            }
        }
    }           
}
Run Code Online (Sandbox Code Playgroud)

当列表被填充然后序列化时,我得到这个 JSON:

"Items": [  
    {  
        "Key":"FirstValue",
        "Value":"One"
    },
    {  
        "Key":"SecondValue",
        "Value":"Two"
    },
    {  
        "Key":"ThirdValue",
        "Value":"Three" …
Run Code Online (Sandbox Code Playgroud)

c# arrays json.net

1
推荐指数
1
解决办法
7253
查看次数

标签 统计

arrays ×1

c# ×1

json.net ×1