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
JSON
{ "Id": "610", "Name": "15", "Description": "1.99", "ItemModList": [] }
what should I write in the ItemModList
A JSON string contains either an array of values, or an object (an associative array of name/value pairs). An array is surrounded by square brackets, [ and ] , and contains a comma-separated list of values. An object is surrounded by curly brackets, { and } , and contains a comma-separated list of name/value pairs.
A resource representation, in the JSON format, is a complex JSON object. Lists of items and nested data structures are represented as JSON arrays and nested JSON objects. A resource that returns a list of items, represents those items in the following standard format: {"data": [{…},{…}]}
JSON NumbersNumbers in JSON must be an integer or a floating point.
' { } ' used for Object and ' [] ' is used for Array in json.
Assuming your ints are 0, 375, 668,5 and 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/
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:
{ "Id": "610", "Name": "15", "Description": "1.99", "ItemModList": [42, 47, 139] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With