• 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; }   
        }
    }
  • 相关阅读:
    1 3
    linux常用命令
    linux的目录结构
    linux的shell编程
    linux的IP配置
    linux安装
    linux简介
    ubuntu16.04上系统管理服务和配置
    PXE
    RPC框架原理
  • 原文地址:https://www.cnblogs.com/yuanfg/p/8963874.html
Copyright © 2020-2023  润新知