zoukankan      html  css  js  c++  java
  • C#修改json文件中的某些值

    using Newtonsoft.Json;
    
    JsonSerializer serialiser = new JsonSerializer();
    string newContent = string.Empty;
                            using (StreamReader reader = new StreamReader(file.FullName))
                            {
                                string json = reader.ReadToEnd();
    
                                dynamic jsonObj = JsonConvert.DeserializeObject(json);
                                jsonObj["course/course"]["tabs"][0]["name"] = "Courseware";
    jsonObj["course/course"]["tabs"][0]["type"] = "courseware";
    
                                jsonObj["course/course"]["tabs"][1]["name"] = "Course Info";
                                jsonObj["course/course"]["tabs"][1]["type"] = "course_info";
                                if (jsonObj["course/course"]["lti_passports"] != null)
                                {
                                    for (int i = 0; i < jsonObj["course/course"]["lti_passports"].Count; i++)
                                    {
                                        string value = jsonObj["course/course"]["lti_passports"][i].ToString();
                                        if (value.Contains("xtreme"))
                                        {
                                            jsonObj["course/course"]["lti_passports"][i] = "test:LeX:test";
                                        }
                                    }
                                }
    
                                for(int i =0; i< jsonObj["course/course"]["advanced_modules"].Count; i++)
                                {
                                    AdvancedModules.Add(jsonObj["course/course"]["advanced_modules"][i].ToString());
                                }
                                jsonObj["course/course"]["catalog_visibility"] = "none";
                                
                                newContent = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
    

      

  • 相关阅读:
    【转】Google 的眼光
    【转】不要去SeaWorld
    【转】Tesla Autopilot
    【转】Tesla Model X的车门设计问题
    【转】Tesla Model S的设计失误
    【转】编程的智慧
    【转】智商的圈套
    【转】创造者的思维方式
    【转】恶评《星际穿越》
    【转】谈创新
  • 原文地址:https://www.cnblogs.com/qixue/p/6484687.html
Copyright © 2011-2022 走看看