Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON for List of int

Tags:

json

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

like image 927
1Mayur Avatar asked Feb 02 '12 14:02

1Mayur


People also ask

Can you have a list in a JSON?

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.

How is a list represented in JSON?

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": [{…},{…}]}

Can JSON have ints?

JSON NumbersNumbers in JSON must be an integer or a floating point.

What is [] and {} in JSON?

' { } ' used for Object and ' [] ' is used for Array in json.


2 Answers

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/

like image 78
MrKiane Avatar answered Sep 21 '22 11:09

MrKiane


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] } 
like image 34
phihag Avatar answered Sep 18 '22 11:09

phihag