zoukankan      html  css  js  c++  java
  • asp.net MVC 框架中控制器里使用Newtonsoft.Json对前端传过来的字符串进行解析

    下面我用一个实例来和大家分享一下我的经验,asp.net MVC 框架中控制器里使用Newtonsoft.Json对前端传过来的字符串进行解析。

    using Newtonsoft.Json;  
    using System;  
    using System.Collections.Generic;  
    using System.Web.Mvc; 
      
    namespace MyWebApp.Controllers  
    {  
        public class TestController : Controller  
        {  
            public ActionResult Index()  
            {  
                try  
                {
              //比如说前端传过来的信息是jsonString
                    string jsonString = "[{"name":"a","value":"1"},{"name":"b","value":"2"}]";  
              string str="";
                    List<kvp> objList = (List<kvp>)JsonConvert.DeserializeObject<List<kvp>>(jsonString ); 
              foreach(var obj in objlist)
              {
                str=str+obj.name+","
              }
              str=str.remove(str.length-1,1);
           } catch (Exception) { throw; } 
           return View(str); 
        } 
      }
        public class kvp
        {  
            public string name { get; set; }   
            public string value { get; set; }   
        }
    }
  • 相关阅读:
    nginx 启动相关的
    爬取豆瓣读书/文件存储数据/数据库存储数据
    python Web 开发三剑客比较
    scrapy
    爬虫自动登录抽屉
    组合搜索
    html瀑布流
    Ajax上传文件/文件预览
    Form组件
    django分页
  • 原文地址:https://www.cnblogs.com/yuanfg/p/8963874.html
Copyright © 2011-2022 走看看