The Newtonsoft.json is used to parse the strings passed by the front end in the controller in ASP.

Source: Internet
Author: User

Here I use an example to share my experience with you, in the ASP. NET MVC Framework, the controller uses Newtonsoft.json to parse the string that is passed through the front end.

usingNewtonsoft.json; usingSystem; usingSystem.Collections.Generic; usingSYSTEM.WEB.MVC; namespaceMywebapp.controllers { Public classTestcontroller:controller { PublicActionResult Index () {Try{//For example, the message from the front is jsonstring.                stringJsonstring ="[{\ "name\": \ "A\", \ "value\": \ "1\"},{\ "name\": \ "b\", \ "value\": \ "2\"}]"; stringStr=""; List<kvp> objlist = (list<kvp>) jsonconvert.deserializeobject<list<kvp>>(jsonstring); foreach(varObjinchobjlist) {STR=str+obj.name+","} str=str.remove (str.length-1,1); } Catch(Exception) {Throw; } returnView (str); }} Public classKVP { Public stringName {Get;Set; }  Public stringValue {Get;Set; } }}

The Newtonsoft.json is used to parse the strings passed by the front end in the controller in ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.