0

I am calling a webservice through ajax call and pass array of object to it after stringify it.

Data after stringifying

data = '[{"para1":"pic 1","para2":"drop 1"},{"para1":"pic 2","para2":"drop 2"}]'

 $.ajax({
        type: 'POST',
        url: "path to url/method",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({
            "data": data
        }),

How to receive it and parse in C# webservice.

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string insertroute(string data){
       //how to parse data here
    }
1

2 Answers 2

1

Your service method will receive the data as a string. You can use the following code to deserialize into a list of objects.

var serializer = new JavaScriptSerializer();
var result = serializer.Deserialize(mail, typeof(List<object>));

As a practice, it would be better if you made a model that matches your json object and passed that into the typeof(List<model>)

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

Comments

0

You need to Convert a string to JSON? You can use something like

var json = JObject.Parse(data);

JObject is from

Newtonsoft.Json

But, you can just send JSON and deal with JSON and sendback JSON no need to stringify it.

Thanks

Steve

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.