|
@@ -1,5 +1,6 @@
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
+using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO;
|
|
@@ -41,26 +42,70 @@ namespace TEAMModelOS.Controllers.Syllabus
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
string contentRootPath = webHostEnvironment.ContentRootPath;
|
|
string contentRootPath = webHostEnvironment.ContentRootPath;
|
|
JsonDocument document = await GetJson(contentRootPath, "/JsonFile/Core/BaseDataDefault.json");
|
|
JsonDocument document = await GetJson(contentRootPath, "/JsonFile/Core/BaseDataDefault.json");
|
|
|
|
+
|
|
|
|
+ string data = getJson(contentRootPath, "/JsonFile/Core/BaseDataDefault.json");
|
|
|
|
+
|
|
|
|
+ JArray parsedJson = JArray.Parse(data);
|
|
if (!request.@params)
|
|
if (!request.@params)
|
|
{
|
|
{
|
|
- List<JsonElement> jsonElements = new List<JsonElement>();
|
|
|
|
- foreach (JsonElement element in document.RootElement.EnumerateArray())
|
|
|
|
|
|
+
|
|
|
|
+ List<JObject> jsonElements = new List<JObject>();
|
|
|
|
+ foreach (JObject element in parsedJson )
|
|
{
|
|
{
|
|
- if (element.TryGetProperty("lang", out JsonElement json))
|
|
|
|
|
|
+ if (element.TryGetValue("lang", out JToken json))
|
|
{
|
|
{
|
|
- if (json.GetString().Equals(request.lang))
|
|
|
|
|
|
+ if (json.ToString().Equals(request.lang))
|
|
{
|
|
{
|
|
jsonElements.Add(element);
|
|
jsonElements.Add(element);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //foreach (JsonElement element in document.RootElement.EnumerateArray())
|
|
|
|
+ //{
|
|
|
|
+ // if (element.TryGetProperty("lang", out JsonElement json))
|
|
|
|
+ // {
|
|
|
|
+ // if (json.GetString().Equals(request.lang))
|
|
|
|
+ // {
|
|
|
|
+ // jsonElements.Add(element);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
return builder.Data(jsonElements).build();
|
|
return builder.Data(jsonElements).build();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- return builder.Data(document.RootElement).build();
|
|
|
|
|
|
+ return builder.Data(parsedJson).build();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static string getJson(string contentRootPath, string name)
|
|
|
|
+ {
|
|
|
|
+ //string webRootPath = _hostingEnvironment.WebRootPath;
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ String path = contentRootPath + name;
|
|
|
|
+ //获取正在占用的文件
|
|
|
|
+ FileStream fs = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
|
|
+ StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
|
|
|
|
+ String line;
|
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
|
+ while ((line = sr.ReadLine()) != null)
|
|
|
|
+ {
|
|
|
|
+ builder.Append(line.ToString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sr.Close();
|
|
|
|
+ string log = builder.ToString();
|
|
|
|
+ return log;
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ var s = e.Message;
|
|
|
|
+ return s;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
public static async Task<JsonDocument> GetJson(string contentRootPath, string name)
|
|
public static async Task<JsonDocument> GetJson(string contentRootPath, string name)
|
|
{
|
|
{
|
|
try
|
|
try
|