c# - How do I create a POST API method that return JSON? -


i c# , .net newbie. need json response instead of task. how do that?

i have controller post method following:

     public task<httpresponsemessage> postdocument() {                //i have code here downloads multipart file           // check if request contains multipart/form-data.         if (!request.content.ismimemultipartcontent())         {             throw new httpresponseexception(httpstatuscode.unsupportedmediatype);         }          //string root = system.web.httpcontext.current.server.mappath("~/app_data");         var provider = new multipartformdatastreamprovider(root);          // read form data , return async task.         var task = request.content.readasmultipartasync(provider).             continuewith<httpresponsemessage>(t =>             {                 if (t.isfaulted || t.iscanceled)                 {                     request.createerrorresponse(httpstatuscode.internalservererror,                                                    t.exception);                 }                   // illustrates how file names.                 foreach (multipartfiledata file in provider.filedata)                 {                     console.writeline(file.headers.contentdisposition.filename);                     console.writeline("server file path: " + file.localfilename);                  }                  return request.createresponse(httpstatuscode.ok);                });           return task;       } 

instead of returning task<>, want return json response json array or json object


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -