用于 int 列表的 JSON
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9114503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON for List of int
提问by 1Mayur
I have a class
我有一堂课
public class ItemList
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<int> ItemModList { get; set; }
}
how should i give the input JSON for list of int as it does not have a key to match its value
我应该如何为 int 列表提供输入 JSON,因为它没有匹配其值的键
JSON
JSON
{
"Id": "610",
"Name": "15",
"Description": "1.99",
"ItemModList": []
}
what should I write in the ItemModList
我应该在 ItemModList 中写什么
回答by MrKiane
Assuming your ints are 0, 375, 668,5 and 6:
假设你的整数是 0、375、668、5 和 6:
{
"Id": "610",
"Name": "15",
"Description": "1.99",
"ItemModList": [
0,
375,
668,
5,
6
]
}
I suggest that you change "Id": "610" to "Id": 610 since it is a integer/long and not a string. You can read more about the JSON format and examples here http://json.org/
我建议您将 "Id": "610" 更改为 "Id": 610,因为它是整数/长整数而不是字符串。您可以在此处阅读有关 JSON 格式和示例的更多信息http://json.org/
回答by phihag
JSON is perfectly capable of expressing lists of integers, and the JSON you have posted is valid. You can simply separate the integers by commas:
JSON 完全能够表达整数列表,并且您发布的 JSON 是有效的。您可以简单地用逗号分隔整数:
{
"Id": "610",
"Name": "15",
"Description": "1.99",
"ItemModList": [42, 47, 139]
}

