0

I know this seems naive. But, I really am struck here!

I have a List<int> which is an input to a Service whose request format is Json.

Example:

List<int> lsId = new List<int>();
lsId.Add(1);
lsId.Add(2);

Now, how to represent this in JSON?

Any help appreciated. Thanks

1 Answer 1

0

JSON representation of that list is this

{
  "lsId": [
    1,
    2
  ]
}

Where "lsId" is the name of the list, and the 1 and 2 inside the [] is the actual content of the list. [] specifies that the value for lsId is a list.
The lsId is enclosed in double quotes because in JSON, identfiers are always strings, and strings in JSON are always with double quotes, not single.

Have a look at http://www.json.org/, its explained pretty well.

5
  • Still, my Method in service gives the count as 0. What would be the issue?
    – Sandeep
    Jun 12, 2014 at 11:47
  • @San I don't know and I can't know because you didn't include the code that does that. But that was not your question
    – Tim
    Jun 12, 2014 at 11:51
  • [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json)] bool Methodname(List<int> lsAssignment); This is my method
    – Sandeep
    Jun 13, 2014 at 8:51
  • @San I dont know about that, but it seems that is an entirely different question.
    – Tim
    Jun 13, 2014 at 8:58
  • Yeah.I know.Thanks anyways Tim for the info passed. Appreciated.
    – Sandeep
    Jun 13, 2014 at 10:40

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.