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);
时间: 2024-12-14 18:47:51