1

I have a JSON array like this:

  "{structChangeList : '[{"structChange":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}]'"

or

"[{"structChangeList":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}]"

and various other variationd which I am trying to pick up with a web method like

    [WebMethod]
    public string receiveStructureUpdates3(List<StrutureData> structChangeList)
    {

        return "Hello World";
    }

where StructureData is:

[DataContract]
public class StrutureData
{
    [DataMember]
    public string id { get; set; }
    [DataMember]
    public string parentId { get; set; }
    [DataMember]
    public string date { get; set; }
}

It works fine when I try to pick up a non array like:

"{"structChange":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}"

with:

    [WebMethod]
    public string receiveStructureUpdates2(StrutureData structChange)
    {
    }

But I can't get the array working. Any ideas?

2 Answers 2

1

EDIT:

To use an array/list, change:

"{"structChange":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}"

To

{"structChange": [{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}]}

Because .Net is looking for structChage, it wants to find that first. Since structChange is a List the value for that key needs to be an array.

Sign up to request clarification or add additional context in comments.

1 Comment

I've already got that code but I don't want to pick up a string in JSON format and then deserialise it, I want to pick up the json directly
0

This is the correct way to send data to an action in the controller

data: "{someField : [[\"Level1.Second\",\"Level1.First\",\"2011-01-01\"]] }

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.