用于List的JSON

1Ma*_*yur 53 json

我上课了

public class ItemList
{
    public long Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public List<int> ItemModList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我应该如何为int列表提供输入JSON,因为它没有匹配其值的键

JSON

{
    "Id": "610",
    "Name": "15",
    "Description": "1.99",
    "ItemModList": []
}
Run Code Online (Sandbox Code Playgroud)

我应该在ItemModList中写什么

MrK*_*ane 97

假设你的整数是0,375,668,5和6:

{
    "Id": "610",
    "Name": "15",
    "Description": "1.99",
    "ItemModList": [
                       0,
                       375,
                       668,
                       5,
                       6
                   ]
}
Run Code Online (Sandbox Code Playgroud)

我建议您将"Id":"610"更改为"Id":610因为它是整数/长而不是字符串.您可以在http://json.org/上阅读有关JSON格式和示例的更多信息.


phi*_*hag 17

JSON完全能够表达整数列表,并且您发布的JSON是有效的.您可以简单地用逗号分隔整数:

{
    "Id": "610",
    "Name": "15",
    "Description": "1.99",
    "ItemModList": [42, 47, 139]
}
Run Code Online (Sandbox Code Playgroud)