asp.net C# 中的 MVC - JSON 视图正在 JSON 架构列表中添加其他 JSON 属性

本文关键字:JSON 列表 属性 其他 添加 net 中的 MVC 视图 asp | 更新日期: 2023-09-27 17:56:04

我在控制器中生成一个 JSON 列表,当我尝试使用 Jsonview 将其传递给视图时,它会使用我的 JSON 结果添加其他属性。我想要这个结果

{"id":"xyz","parent":"#","text":"folder"}

但它显示

[{"Id":".","Type":null,"Default":null,"Properties":{},"Items":[],"ItemsPositionValidation":false,"Required":[],"AllOf":[],"AnyOf":[],"OneOf":[],"Not":null,"Enum":[],"UniqueItems":false,"MinimumLength":null,"MaximumLength":null,"Minimum":null,"Maximum":null,"ExclusiveMinimum":false,"ExclusiveMaximum":false,"MinimumItems":null,"MaximumItems":null,"MinimumProperties":null,"MaximumProperties":null,"ExtensionData":{"parent":[],"text":[]},"Title":null,"Description":null,"MultipleOf":null,"Pattern":null,"Dependencies":{},"AdditionalProperties":null,"PatternProperties":{},"AllowAdditionalProperties":true,"AdditionalItems":null,"AllowAdditionalItems":true,"Format":null}

asp.net C# 中的 MVC - JSON 视图正在 JSON 架构列表中添加其他 JSON 属性

public ActionResult list()
{
         Uri firstUrl = new Uri("ftp.xyz.com");
            List<JSchema> tst = DisplayList(firstUrl);
            return View(tst);
        }

 public static List<JSchema> DisplayList(Uri serverUri)
        {
            List<String> tet = new List<String>();
            FtpWebRequest Request = (FtpWebRequest)WebRequest.Create(serverUri);
            Request.Credentials = new NetworkCredential("username", "password");
            Request.Method = WebRequestMethods.Ftp.ListDirectory;
            FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
            Stream ResponseStream = Response.GetResponseStream();
            StreamReader Reader = new StreamReader(ResponseStream);
            //JSchema sch =  JSchema.Parse(jsonsch);
            int counter = 0; 
            while (!Reader.EndOfStream)//Read file name
            {
                string temp = Reader.ReadLine();
                tet.Add( @"{'id' : '" + temp + "', 'parent' : '#','text' :'" + temp + "' }");
                counter++;
            }// end while
            List<JSchema> js = new List<JSchema>();
            for (int i =0; i<counter ; i++ )
            {
               js.Add ( JSchema.Parse(tet[i]));
            }
            Response.Close();
            ResponseStream.Close();
            Reader.Close();
            return js;

        }// end display list